Productivity Spotlight: JBoss Forge, JRebel and the Golden Days of Java Development

When I’m not fighting crime in the dark hours of the morning, I frequently need to create a small demo application or enhance an existing one, ideally using some framework, in my day job as JRebel Product Lead at ZeroTurnaround. For this kind of task, it is really sweet to have a tool that can suggest different actions for me to get geeky with in an existing piece of code.

I was recently asked by ZeroTurnaround Marketing guy Oliver to explain JBoss Forge in dummy terms, so I told him that Forge is a generator, mainly targeted towards Java EE apps, that helps devs simplify building up an advanced “application blueprint” using familiar wizard-based and CL auto-completions. He was like, “What?”

The problem is that although IDEs like Eclipse, IntelliJ IDEA and NetBeans are quite good for editing your code, none of them actually provide the means to execute tasks a-la “add framework X to my project and generate a UI for this and that”.

About a year ago, I stumbled upon Forge when the project was relatively new. Its purpose is to be a “next-generation shell for tooling and automation at a command line level” and it looks like the claim is totally valid. After testing it out myself, I determined that with the tools’ context-aware autocompletion, it is just awesome to use.

With Forge, you can either start a new project from scratch and generate the exoskeleton for your application just with a few commands. But it can also be used for incremental enhancements for your existing projects using extra plugins [https://docs.jboss.org/author/display/FORGE/Installing+new+Plugins].

Plus, Forge is designed to be used on any kind of Maven project. And if you can combine all of this with the power of JRebel, which lets you just code like mad and avoid the restart/redeploy cycle altogether, then you’ve really got something. Let’s see what kind of trouble we can get in…

Getting started

Just for a quick start, here’s what you need to do to create a new project with Forge:

  1. start the shell:
    $ forge
  2. create the new project using 'new-project' command:
    $ new-project --named myproject --topLevelPackage com.zt --type war 
    --projectFolder myproject

And now you have a new Maven project. If I for some reason I forget the names of the parameters that I need to pass to the 'new-project' command, I can just press [TAB] and the shell suggests what I could type next.

Arguably, generating a new project isn't Forge's greatest value - the same could be achieved with Maven archetypes, plus integration with archetypes is apparently planned already: [https://issues.jboss.org/browse/FORGE-273].

The sweet part of Forge is that now you have the luxury of defining your own application skeleton interactively, after it has already been generated. This means that you can create the project using the Maven archetype first, and then extend it using Forge's intuitive suggestions.

Use the Forge, Luke!

Given Forge's value for extending an existing project, let's see how to set that up. We can use a quickstart [https://github.com/jbossas/quickstart] project as an example either by cloning it from GitHub, or we can create a sample project using the JBoss Tools plugin for Eclipse.

Once the project is generated, we can now use Forge to complement the project. For the sake of this example, let's see how we can apply a scaffolding plugin.

Using a scaffolding plugin we could now generate the CRUD interface for existing entities:

$ scaffold setup --targetDir admin
$ richfaces setup
$ scaffold from-entity org.jboss.as.quickstarts.kitchensink.model.* 
--targetDir admin --overwrite

If we start the application now, we'll see the brand new interface of the application:

Since the sample project had only one entity configured, we can see the lonely member button on the screenshot.

Forge Scaffolded UI

This is a nice example of adding a new framework to the application with some simple functionality. I'm really excited to see more plugins like this capable of installing Spring, Struts or Vaadin to my application and then getting to setup something cool and functional on top of the existing code. Luckily, Forge is incredibly easy to extend with your own plugins for solving just about any problem you might get stuck with.

Add JRebel, Stir and Bake

If you haven't heard of JRebel before, well, at this point I can only say "Wat?" ;-) We're approaching 2013 already, why the heck are you still redeploying in Java?

JRebel requires a small configuration file to locate the resources - rebel.xml - which can be generated using a Maven plugin. Luckily, there's a Forge plugin that can setup the JRebel Maven plugin for us.

I don't think it's very hard to copy a piece of XML to your pom.xml manually, but I enjoy going all command line on its butt:

$ forge install-plugin jrebel
$ jrebel setup
$ build

This will setup the basic configuration for JRebel Maven plugin and once the Maven build is executed, rebel.xml will be generated for all the modules in the project and stored into the correct location for each module, thereby letting you use JRebel to code without restarts. The current JRebel plugin for Forge doesn't provide any other options to setup the Maven plugin yet, so if you feel like being a bit of an activity, feel free to submit pull requests [https://github.com/ctpconsulting/forge-jrebel-plugin] :)

Applying JRebel

After the rebel.xml configuration file is generated, we can deploy the application archive to the server. JBoss Forge even provides plugins for application deployment, but after discussing it I figured that due to fact that most developers use an IDE anyway (presumably Eclipse), I will proceed with the IDE rather than deploy the application using Forge.

So I'd rather open up the IDE, configure the required application sever, say JBossAS 7, enable the JRebel checkbox in server configuration settings and boot the container with JRebel. Are you with me?

Oh, JBoss Tools comes with the integrated Forge console actually, so we could execute Forge commands right from the Eclipse.

Conclusion

For me, JBoss Forge is huge leap ahead of Maven archetypes - it is an intuitive, simple way to interactively add more bricks to your existing project without going through all the manual. Whenever I need to create quick demo applications, or add/change existing ones, I find Forge to be a great tool, especially when complemented with JRebel - intelligence, speed and code, together at last!

Thanks for reading, you can get in touch with me via Twitter @antonarhipov or reach me at anton@zeroturnaround.com.


About the Author

Anton Arhipov is JRebel Product Lead at ZeroTurnaround. He is a Java enthusiast, vim fan and IntelliJ addict. Professional interests include programming languages, middleware and tooling. Anton loves tea and doesn't drink coffee. He tweets from @antonarhipov.

, ,

About rayploski

I'm lucky enough to have a dream job. I run developer strategy for Red Hat.

View all posts by rayploski

Trackbacks/Pingbacks

  1. Productivity Spotlight: JBoss Forge, JRebel and the Golden Days of Java Development | Development Topics | Scoop.it - August 24, 2012

    [...] When I’m not fighting crime in the dark hours of the morning, I frequently need to create a small demo application or enhance an existing one, ideally using some framework, in my day job as J…  [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 115 other followers

%d bloggers like this: