For those who creates many small web applications, like proof of concepts, know how much time you can loose by setting up the project structure. Creating the pom file, web application file, faces configuration etc. And although there exists maven archetypes, they doesn't allows suite your needs. For a lot of tests, you need slightly different options and required dependencies.
And this is where JBoss Forge can help you. It is a command line driven tool that helps you in those repetitive tasks. And, a very important aspect for me, is the fact that it doesn't place any marker in your files or project. In fact, it can be used on a project which isn't created with JBoss Forge by interpreting the files it find.
I came to this tool in my search for something that could help me in creating a project setup according to our company standards for JEE6 projects. By default, JBoss Forge has the capability of creating a project that uses the JEE6 technology stack. But it doesn't go far enough, or we have requirements that goes much further. We want to be able to setup multiple projects for quality control (PMD, Findbugs, etc), model and services project, view project, functional testing project and so on.
The basic building blocks, but sometimes quit sophisticated, are already available. And creating plugins is very easy. So, everyone has to start with some easy things and thus I started by creating a plugin that is able to add the PrimeFaces component library.
Not from scratch
You can learn a lot by looking at some example code. And in my case, there was already someone that started with such a plugin (see https://github.com/kukel/forge-plugin-primefaces.git, by Ronald van Kuijk) Trying his code, there where some compilation problems, due to the fact that JBoss Forge is still in beta and his code was coded against a previous version, and things like scaffolding that I never use. With scaffolding, you can create default screens that are able to view, insert and update from a database table. They can be very handy in prototyping but in real world applications, they are never needed.
So I took his code, removed the scaffolding, made it compatible with the latest API (beta 3), added support for the latest PrimeFaces 3 release (with the new namespace declaration) and detection of CDI capabilities in the project.
By just typing 'primefaces' at the JBoss Forge command prompt, you get information about the status of the project. When PrimeFaces is installed, it specifies which version (2 or 3) and otherwise you get information about how it can be added to the project.
Adding some kind of functionality is mostly done in JBoss Forge by specifying the setup command. With the PrimeFaces plugin you can achieve it by issuing the command 'primefaces setup'. This will convert your project to a war artifact, installs the other required dependencies like servlet (the web.xml) and JSF (the faces-config.xml), and adds the maven dependencies after you have selected the version of PrimeFaces you want.
Before you execute this command, you should always verify if you are in the correct project. The standard JSF setup adds also some files related to the error handling and they can overwrite some files which already exists in your project. But with a good version control system, you don't have to worry about this.
The last command I describe here, is to add an example to the project, by issuing the command 'primefaces install-example-facelet'. It replaces the current index.xhtml file, so your are warned again, with an XHTML JSF file that uses a template and shows a value from a property from a managed bean. When the plugin detects CDI artifacts in the project, the managed bean is defined with the javax.inject and javax.enterprise annotations. Otherwise plain JSF2 annotations are used.
There are other command which are supported by the plugin. They are created by Ronald and kept in the code base. But they aren't very well tested so you can use them if you want to try them out.
And in fact, the plugin is also in some kind of beta phase. It should work but there are probably situations where it will fail. In that case you can contact me and I'll have a look at your problem and try to solve it or you can follow the git philosophy and fork it and implement the solution yourselve.
May the forge be with you ;-)
Oh, before I forget it, here you can find the code https://github.com/rdebusscher/forge-plugin-primefaces.