Hello and welcome to my blog!
In my first posting I want to show how to create a maven based Java EE project within 5 minutes with JBoss Forge. We will create a project with two entities (Book and Author) and a web interface to create, search and edit these objects.This is the first part of my JBoss Forge series:
- JBoss Forge - Speedup your enterprise development
- JBoss Forge - Speedup your enterprise development - Part II RESTful Webservices
- JBoss Forge - Speedup your enterprise development - Part III Integration Tests with Arquillian
Getting JBoss Forge
The easiest way to get JBoss Forge is to use JBoss Tools or JBoss Developer Studio. You can find both in the Eclipse Marketplace.After installing the plugin to your eclipse, you need to start the Forge Console to get the command line interface.
Create the project
We could spend some time to create the project with the eclipse wizard and to setup the maven build process. But using Forge is much easier and faster. By entering the following command to the Forge Console we are getting a project ready to start with the real work:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new-project --named ForgeExample --topLevelPackage blog.thoughts.on.java.forge |
Generate Persistence
OK, now we can start to build our application. Lets do the persistence first.In the past we created - or most often copied - the persistence.xml file. Now we can use Forge to create the persistence.xml file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
persistence setup --provider HIBERNATE --container JBOSS_AS7 |
Forge keeps the Package Explorer up to date and opens the persistence.xml in an editor:
Now we can start to generate our entities. First we create the entity Book with a title as String, the publicationDate as Date and the number of pages as int. This can be done in four lines by using the commands entity and field:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
entity --named Book | |
field string --named title | |
field temporal --type DATE --named publicationDate | |
field int --named pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
field oneToMany --named books --fieldType blog.thoughts.on.java.forge.model.Book.java --inverseFieldName author |
Generate Web UI
Now we are only missing the web interface for the created entities. Therefore we setup the scaffolding and generate the web interface from our entities. In this example we use the default scaffold type JavaServer Faces.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scaffold setup | |
scaffold from-entity blog.thoughts.on.java.forge.model.* |
After the generation is done, we can build our application by calling build or by using the normal maven commands.
Deployment
As a last step we want to deploy our application to a JBoss AS7 instance. This can be done with the AS7 Forge Plugin. Therefore we need to install and configure it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
forge install-plugin jboss-as-7 | |
as7 setup |
Now we can start the server and deploy the application by calling a7 deploy.
OK, lets have a look at our application:
Conclusion
We created a Java EE project in less than 5 minutes by using just a few commands of JBoss Forge. But you can do much more with JBoss Forge. In my next post I will show you how to generate a webservice interface for our application and how to use the arquillian plugin to test it.Links
http://forge.jboss.org/
http://www.youtube.com/watch?v=Clso5vtKu9k
JBoss Forge Series
- JBoss Forge - Speedup your enterprise development
- JBoss Forge - Speedup your enterprise development - Part II RESTful Webservices
- JBoss Forge - Speedup your enterprise development - Part III Integration Tests with Arquillian
This looks exactly like Spring Roo (even syntactically): http://en.wikipedia.org/wiki/Spring_Roo
ReplyDeleteWhere's the difference?
Thank you for your question.
ReplyDeleteForge and Spring Roo are similar in several aspects. The main difference for me is, that Spring Roo and the generated projects are tied to Spring (generated projects work on top of Spring). Projects created by Forge are only based on Maven. So the Forge approach is far more generic than Spring Roo.
The Forge FAQ provides a more detailed answer for your question: http://forge.jboss.org/docs/using/faq.html#roo
Great work - Forge and your article as well! As a shell enthusiast I like the use of Forge as some kind of project shell. Really curious to see the next part of your tutorial. BTW: Don't miss to include examples of the scripting features. :-)
ReplyDeleteThank you Ronny!
DeleteThe next part is already up: http://somethoughtsonjava.blogspot.de/2013/09/rapid-application-development-with.html
And I will post a third part beginning of next week :)
Hi, thanks for the quick reply. I just watched a 1hr demo on it and im quite impressed. Thanks for the tip! I reckon ill give it a shot.
ReplyDelete