Archive

Posts Tagged ‘eclipse’

Setting up JBOSS AS7 with eclipse

April 26, 2012 1 comment

I recently got a chance to try out JBOSS AS7 as application server container for the upcoming project and I must say that JBOSS is no longer the monotithic,tiring,heavy and problamatic server anymore.It took me 4 seconds to run the server, which is fascinating considering the legacy.  Parallel deployment. quick startup,lightweight, powerful feature etc are some nifty features on offer

So, as part of the initial requirement, we have to setup a maven based project and then deploy that onto JBoss AS7 through Eclipse and trust it was’nt a piece of cake and henceforth I decided to  write a post about it.

  1. Download and unzip JBoss AS7 from http://www.jboss.org/jbossas/downloads/ to a convenient location
  2. Create a basic maven project from maven quickstart archtype.
  3. This is optional step if you are planning to use JBoss external to Eclipse.
  4. Download JBoss Tool for Eclipse from the following update site. You will only need to install JBoos AS Tools for registering/creating a server.This is optional step if you are planning to use JBoss external to Eclipse.
  5. Setup a JBoss Community Server within eclipse,Server->JBoss AS7 by providing the path to JBoss folder. This will help you in displaying the logs in eclipse console.
  6. AS7 currently deploys wars that are present within standalone/deployments folder.

The problem was how to deploy the war file into JBoss automatically from eclipse.  The steps follwoed with tomcat did not work and I had to come up with some different solution. I thought against making the changes in JBoss configuration.So, I thought that maven creates a war in target folder by default.We can change the o/p directory such that the war is created within the standalone/deployments folder. This way our updated war reaches JBoss each time we build the project and since JBoss is running within it would be automatically deployed, and I can track the log messages in the console.

To achieve this I used the maven-war-plugin in pom.xml. I configured the plugin to set the OutputDirectoy to the standalone/deployment folder.And Voila, it worked, so we were able to wire our project with JBoss seamlessly and also were able to reload the context automatically without going through the pains of understanding the JBoss configurations.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <outputDirectory>/path/to/standalone/deployment</outputDirectory>
  </configuration>
 </plugin>

Also through AS7 Maven Plugin
Add the following maven plugin info in pom.xml

 <pluginRepository>
   <id>jboss-public-repository-group</id>
   <name>JBoss Public Maven Repository Group</name>
   <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
 </pluginRepository>

<plugin>
 <groupId>org.jboss.as.plugins</groupId>
 <artifactId>jboss-as-maven-plugin</artifactId>
 <version>7.1.1.Final</version>
 <configuration>
  <hostname>localhost</hostname>
  <port>9999</port>
  <filename>${project.build.finalName}.${project.packaging}</filename>
  <webModule>
   <groupId>${project.groupId}</groupId>
   <artifactId>${project.artifactId}</artifactId>
   <contextRoot>/test</contextRoot>
  </webModule>
 </configuration>
</plugin>

The execution can be configured through the following entry, which says if the maven phase is package then next linked goal should be delpoy

 

<executions>
  <execution>
   <phase>package</phase>
   <goals>
      <goal>deploy</goal>
   </goals>
  </execution>
</executions>