Skip to content

1 create project from maven

hantsy edited this page Apr 14, 2017 · 3 revisions

Create a Java EE project from Maven archetype

Apache Maven officially provides a few templates to create general purpose Java EE projects, in the Maven world, they are named archetype. There are several archetypes under group org.codehaus.mojo.archetypes can be used to create EAR, appclient, or simple web applications.

The following is an example of creating a Java EE 7 web applicaiton.

mvn archetype:generate

Read this article from DZone for more details.

NetBeans IDE provides built-in support for these archetypes when create a Maven based Java EE project from New Project wizard.

Wildfly also provide a few archetype which are ready for Java EE 7 and Wildfly application server.

Most of time, I used Wildfly as target application server in projects. In the following sample I will use the archetype wildfly-javaee7-webapp-blank-archetype under group id org.wildfly.archetype to create the project skeleton.

Create project

Open your terminal, use command mvn archetype:generate to generate the project skeleton.

mvn archetype:generate 

Before you run the command, you can browse org.wildfly.archtype in

Luckily, almost all of the popular IDEs, such as Intellij IDEA, NetBeans, JBoss Developer Studio have provided friendly wizards to create project from Maven archetypes step by step.

Explore the generated codes

Import the project you have just created into JBoss Developer Studio.

Open Package view, you will see the following project structure.

empty java ee project

Beside the pom.xml file, it just includes some specific files for different Java EE specification.

  1. src/main/resources/META-INF/persistence.xml is the JPA configuration file.
  2. src/main/webapp/WEB-INF/beans.xml is the default CDI configuration file. NOTE: in Java EE 7, CDI is enabled by default. So beans.xml is not required to activiate it when use CDI in Java EE 7..
  3. src/main/webapp/WEB-INF/blog-api-ds.xml is a Wildfly specific DataSource definition file. NOTE: the postfix -ds in the name is a must, else Wildfly can not detect it when deploy it into the server.
  4. src/main/webapp/WEB-INF/faces-config.xml is the JSF configuration file. But we will focus on JAXRS to implement RESTful APIs in this sample, so this file is no use and can be deleted.

Open the pom.xml file.

Unlike the former posts which used JBoss Enterprise repository by default, in this project, we generated the project skeleton from a wildfly specific maven archetype, all dependencies are Wildfly specific.

  1. wildfly-maven-plugin allows you deploy and undeploy via maven command line.

  2. There are several maven profiles defined. arq-wildfly-remote and arq-wildfly-managed are ready for JBoss Arquillian test. openshift for OpenShift Cloud deployment.


The difference between arq-wildfly-remote and arq-wildfly-managed is the former requires a running Wildfly server before run the test codes, and the later Arquillian will manage the Wildfly itself.

Update to Wildfly 10

We will use the latest Wildfly, aka 10.0.0.Final. We have to the dependencies to Wildfly 10.0.0.Final.

Some changes you have to be careful about.

The Wildfly Arquillian dependency groupId was changed to org.wildfly.arquillian.

Add the latest Arquillian BOM in the dependencyManagement fragment, and change the arq-wildfly-managed profile to the following.

	<!-- An optional Arquillian testing profile that executes tests in your 
	WildFly instance -->
	<!-- This profile will start a new WildFly instance, and execute the test, 
	shutting it down when done -->
	<!-- Run with: mvn clean test -Parq-wildfly-managed -->

It will download Wildfly 10 and start it before run a test, and stop it after the test running is complete. No need an external Wilfly server.

Deploy and run

The wildfly maven plugin is available in pom.xml, you can use it to deploy, undeploy this project into our Wildfly application server.

  1. Make sure your Wildfly application server is running.
  2. Execute mvn wildfly:deploy -DskipTests to deploy the project into Wildfly application server.
  3. You can run mvn wildfly:undeploy to undeploy it.

In the next steps, I will try to create the similar APIs in angularjs-springmvc-sample-boot, but use Java EE 7/Wildfly/JAXRS to implement it. As the angularjs-springmvc-sample-boot, the test codes will be available. We will use Wildfly as default server, and use JBoss Arquillian to test the Java EE components in Wildfly container.

You can’t perform that action at this time.