Saturday, January 19, 2013

JBoss 7.1.1, Eclipse Juno and Maven integration for blazing fast deployments

    Every time I want to gain some knowledge about new technology I create environment for that in order to touch the code. Such environment should respond very quickly for changes in the code so as I can see the effects immediately.
When it comes to Java EE, JBoss 7.1.1 is a perfect candidate that can act as the heart of the ecosystem. It starts very fast and is well integrated with Eclipse IDE for Java EE Developers. Moreover, those two works well on JDK7u10. But there are some steps that must be performed to integrate JBoss, Eclipse and Maven.
After you execute Eclipse for the first time, make sure that you use JDK instead of JRE (Window->Preferences):
Next, you have to install two plugins (Help->Eclipse Marketplace...) for Maven:
Maven Integration for Eclipse contains embedded Maven3 so you do not need to install it separately. Next plugin that you should install is JBoss Tools (Juno). There is plenty of stuff under the umbrella of this plugin but for now you should just install JBossAS Tool. This is everything you need for the integration. Now, you can add a new server (Window->Preferences) :
and a new Maven application (File->New->Other...->Maven Project). Choose: org.apache.maven.archetypes:maven-archetype-webapp as the archetype. Next, thanks to Maven Integration for Eclipse WTP plugin, you can right click on the project and select Run As -> Run on Server. Then the logs will be printed on the console:
[org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 1108ms...
[org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of "jboss-maven.war"
[org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /jboss-maven
[org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "jboss-maven.war"
The application is deployed in the exploded mode - the folder with the application is copied to:
\jboss\standalone\deployments
If you prefer deploying as archives (e.g. war, ear) you can select such an option in the server properties. Just double click on the server in the Servers tab:
 
and mark the appropriate checkbox:
Now, after modifying the code, all you need is hitting CTRL+S and in a few seconds the changes are deployed:
[org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015877: Stopped deployment jboss-maven.war in 30ms
[org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "jboss-maven.war"
[org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /jboss-maven 
[org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018565: Replaced deployment "jboss-maven.war" 
with deployment "jboss-maven.war" 
You can adjust the time after which the changes will be deployed. Just go to:
\jboss\standalone\configuration\standalone.xml
set the scan-interval in milliseconds:
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="1000"/>
</subsystem> 
and restart the server. Now, after code modification and saving, the changes will be deployed within 1 second.

Of course deployments of complicated projects with complex build process and lots of external dependencies are much harder. However, the example that I have provided is perfect for small applications that allow you to learn the technology.

1 comment :