How to convert a JBoss Developer Studio web project to a Maven project (JB225)

by Jim Rigsbee (Red Hat)

In this article, we will convert a web project generated by the JBoss Developer Studio CDI Web Project wizard to a Maven project. Doing so will give you the power of the Maven build system with its dependency management, build life cycles, and automated JEE packaging abilities. Follow these steps:

a. Right click on the project name in the Project Explorer tree and select Configure → Convert to Maven Project… In the wizard steps be sure to select WAR packaging.

b. Configure the Java SE 6 compiler plugin so that we can process annotations. Add this to pom.xml file:

<build>
	<plugins>
		<plugin>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.6</source>
				<target>1.6</target>
			</configuration>
		</plugin>
	</plugins>
</build>

c. Move the contents of the WebContent to the src/main/webapp folder. Delete the WebContent folder.

d. Create or convert the source folder to src/main/java. Based on your project’s needs and existing code you may also need to add or convert:

  • src/main/resources
  • src/test/java
  • src/test/resources

e. To automatically manage JEE specification library version numbers, add the JEE 6 specification dependency management BOM to the pom.xml file:

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.jboss.spec</groupId>
			<artifactId>jboss-javaee-6.0</artifactId>
				<version>3.0.0.Beta1</version>
				<type>pom</type>
				<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

f. Generate a model Maven project so that you can borrow the dependencies: Use JBoss Central and pick the Java EE Web Project:

Java EE Web Project

g. Copy the JEE 6 specification dependencies from the model project pom.xml to your project’s pom.xml. Based on your project’s needs consider including these artifacts:

  • cdi-api
  • jboss-annotations-api_1.1_spec
  • jboss-jaxrs-api_1.1_spec
  • hibernate-jpa-2.0-api
  • jboss-ejb-api_3.1_spec
  • jboss-transaction-api_1.1_spec
  • jboss-jsf-api_2.1_spec
  • jboss-servlet-api_3.0_spec
  • jboss-jaxb-api_2.2_spec
  • hibernate-validator

g. Right click on the project name in the Project Explorer and select Maven → Update Project Configuration…

h. Consider adding the JBoss AS plugin so that you can deploy to JBoss EAP with Maven. Add the following to the plugins section of the pom.xml file:

<plugin>
	<groupId>org.jboss.as.plugins</groupId>
	<artifactId>jboss-as-maven-plugin</artifactId>
	<version>7.1.0.Beta1b</version>
</plugin>

Now you can develop, build, and deploy inside the JBoss Developer Studio as well as build from the command line. Make sure you have the JBOSS_HOME environment variable set to the installation directory of JBoss EAP. Use the following Maven command to build and deploy your application:

mvn package jboss-as:deploy

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

  1. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and create my own.
    Do you need any html coding expertise to make your own blog?
    Any help would be really appreciated!

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