Monday, January 18, 2016

Create Java EE7 project from JBoss Wildfly Maven archetype

JBoss Wildfly Maven plugin
https://docs.jboss.org/wildfly/plugins/maven/latest/index.html 

http://mvnrepository.com/artifact/org.wildfly.archetype/wildfly-javaee7-webapp-ear-archetype/8.2.0.Final

First try with Adam Bien's Minimalistic pom.xml
http://www.adam-bien.com/roller/abien/entry/setting_up_java_ee_7

[dave@localhost wildfly]$ mvn archetype:generate -Dfilter=com.airhacks:javaee7-essentials-archetype


Define value for property 'groupId': : dave
Define value for property 'artifactId': : dave-java-ee7-minimal
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  dave: : 
Confirm properties configuration:
groupId: dave
artifactId: dave-java-ee7-minimal
version: 1.0-SNAPSHOT
package: dave
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: javaee7-essentials-archetype:1.3
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-java-ee7-minimal
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-java-ee7-minimal
[INFO] project created from Archetype in dir: /home/dave/git/wildfly/dave-java-ee7-minimal


Files created from Maven  archetype

[dave@localhost wildfly]$ find
.
./dave-java-ee7-minimal
./dave-java-ee7-minimal/pom.xml
./dave-java-ee7-minimal/src
./dave-java-ee7-minimal/src/main
./dave-java-ee7-minimal/src/main/webapp
./dave-java-ee7-minimal/src/main/webapp/WEB-INF
./dave-java-ee7-minimal/src/main/webapp/WEB-INF/beans.xml
./dave-java-ee7-minimal/src/main/resources
./dave-java-ee7-minimal/src/main/java
./dave-java-ee7-minimal/src/main/java/com
./dave-java-ee7-minimal/src/main/java/com/airhacks
./dave-java-ee7-minimal/src/main/java/com/airhacks/JAXRSConfiguration.java


Generated pom.xml


[dave@localhost dave-java-ee7-minimal]$ more pom.xml 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>dave</groupId>
    <artifactId>dave-java-ee7-minimal</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>dave-java-ee7-minimal</finalName>
    </build>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
</project>


Using Wildfly Maven archetype
https://docs.jboss.org/wildfly/plugins/maven/latest/index.html

[dave@localhost wildfly]$ mvn archetype:generate -Dfilter=wildfly-javaee7-webapp-ear-archetype


1: remote -> org.wildfly.archetype:wildfly-javaee7-webapp-ear-archetype (An archetype that generates a starter Java EE 7 webapp project for JBoss Wildfly. The project is an EAR, with an EJB-JAR and WAR)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 
Choose archetype:
1: remote -> org.wildfly.archetype:wildfly-javaee7-webapp-ear-archetype (An archetype that generates a starter Java EE 7 webapp project for JBoss Wildfly. The project is an EAR, with an EJB-JAR and WAR)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Choose org.wildfly.archetype:wildfly-javaee7-webapp-ear-archetype version: 
1: 8.1.0.Final
2: 8.2.0.Final
Choose a number: 2: 2


Define value for property 'groupId': : dave
Define value for property 'artifactId': : dave-java-ee7-wildfly-full
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  dave: : 
Confirm properties configuration:
groupId: dave
artifactId: dave-java-ee7-wildfly-full
version: 1.0-SNAPSHOT
package: dave
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: wildfly-javaee7-webapp-ear-archetype:8.2.0.Final
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-java-ee7-wildfly-full
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: dave-java-ee7-wildfly-full
[INFO] Parent element not overwritten in /home/dave/git/wildfly/dave-java-ee7-wildfly-full/dave-java-ee7-wildfly-full-ejb/pom.xml
[INFO] Parent element not overwritten in /home/dave/git/wildfly/dave-java-ee7-wildfly-full/dave-java-ee7-wildfly-full-web/pom.xml
[WARNING] CP Don't override file /home/dave/git/wildfly/dave-java-ee7-wildfly-full/dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF/templates/default.xhtml
[INFO] Parent element not overwritten in /home/dave/git/wildfly/dave-java-ee7-wildfly-full/dave-java-ee7-wildfly-full-ear/pom.xml
[INFO] project created from Archetype in dir: /home/dave/git/wildfly/dave-java-ee7-wildfly-full


[dave@localhost dave-java-ee7-wildfly-full]$ find
.
./pom.xml
./README.md
./dave-java-ee7-wildfly-full-ear
./dave-java-ee7-wildfly-full-ear/pom.xml
./dave-java-ee7-wildfly-full-ear/src
./dave-java-ee7-wildfly-full-ear/src/main
./dave-java-ee7-wildfly-full-ear/src/main/application
./dave-java-ee7-wildfly-full-ear/src/main/application/META-INF
./dave-java-ee7-wildfly-full-ear/src/main/application/META-INF/dave-java-ee7-wildfly-full-ds.xml
./dave-java-ee7-wildfly-full-ejb
./dave-java-ee7-wildfly-full-ejb/pom.xml
./dave-java-ee7-wildfly-full-ejb/src
./dave-java-ee7-wildfly-full-ejb/src/main
./dave-java-ee7-wildfly-full-ejb/src/main/resources
./dave-java-ee7-wildfly-full-ejb/src/main/resources/import.sql
./dave-java-ee7-wildfly-full-ejb/src/main/resources/META-INF
./dave-java-ee7-wildfly-full-ejb/src/main/resources/META-INF/persistence.xml
./dave-java-ee7-wildfly-full-ejb/src/main/resources/META-INF/beans.xml
./dave-java-ee7-wildfly-full-ejb/src/main/java
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/model
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/model/Member.java
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/service
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/service/MemberRegistration.java
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/data
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/data/MemberListProducer.java
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/data/MemberRepository.java
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/util
./dave-java-ee7-wildfly-full-ejb/src/main/java/dave/util/Resources.java
./dave-java-ee7-wildfly-full-ejb/src/test
./dave-java-ee7-wildfly-full-ejb/src/test/resources
./dave-java-ee7-wildfly-full-ejb/src/test/resources/arquillian.xml
./dave-java-ee7-wildfly-full-ejb/src/test/resources/META-INF
./dave-java-ee7-wildfly-full-ejb/src/test/resources/META-INF/test-persistence.xml
./dave-java-ee7-wildfly-full-ejb/src/test/resources/test-ds.xml
./dave-java-ee7-wildfly-full-ejb/src/test/java
./dave-java-ee7-wildfly-full-ejb/src/test/java/dave
./dave-java-ee7-wildfly-full-ejb/src/test/java/dave/test
./dave-java-ee7-wildfly-full-ejb/src/test/java/dave/test/MemberRegistrationTest.java
./dave-java-ee7-wildfly-full-web
./dave-java-ee7-wildfly-full-web/pom.xml
./dave-java-ee7-wildfly-full-web/src
./dave-java-ee7-wildfly-full-web/src/main
./dave-java-ee7-wildfly-full-web/src/main/webapp
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/css
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/css/screen.css
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx/asidebkg.png
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx/dualbrand_logo.png
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx/bkg-blkheader.png
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx/wildfly_400x130.jpg
./dave-java-ee7-wildfly-full-web/src/main/webapp/resources/gfx/headerbkg.png
./dave-java-ee7-wildfly-full-web/src/main/webapp/index.xhtml
./dave-java-ee7-wildfly-full-web/src/main/webapp/index.html
./dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF
./dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF/templates
./dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF/templates/default.xhtml
./dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF/faces-config.xml
./dave-java-ee7-wildfly-full-web/src/main/webapp/WEB-INF/beans.xml
./dave-java-ee7-wildfly-full-web/src/main/java
./dave-java-ee7-wildfly-full-web/src/main/java/dave
./dave-java-ee7-wildfly-full-web/src/main/java/dave/controller
./dave-java-ee7-wildfly-full-web/src/main/java/dave/controller/MemberController.java
./dave-java-ee7-wildfly-full-web/src/main/java/dave/util
./dave-java-ee7-wildfly-full-web/src/main/java/dave/util/WebResources.java
./dave-java-ee7-wildfly-full-web/src/main/java/dave/rest
./dave-java-ee7-wildfly-full-web/src/main/java/dave/rest/MemberResourceRESTService.java
./dave-java-ee7-wildfly-full-web/src/main/java/dave/rest/JaxRsActivator.java
./dave-java-ee7-wildfly-full-web/src/test
./dave-java-ee7-wildfly-full-web/src/test/java


Generated pom.xml
[dave@localhost dave-java-ee7-wildfly-full]$ more pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!--
    JBoss, Home of Professional Open Source
    Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
    contributors by the @authors tag. See the copyright.txt in the
    distribution for a full listing of individual contributors.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <name>dave-java-ee7-wildfly-full</name>
    <modelVersion>4.0.0</modelVersion>
    <groupId>dave</groupId>
    <artifactId>dave-java-ee7-wildfly-full</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <url>http://wildfly.org</url>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <distribution>repo</distribution>
            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>
    <modules>
        <module>dave-java-ee7-wildfly-full-ejb</module>
        <module>dave-java-ee7-wildfly-full-web</module>
        <module>dave-java-ee7-wildfly-full-ear</module>
    </modules>

    <properties>
        <!-- Explicitly declaring the source encoding eliminates the following 
            message: -->
        <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
            resources, i.e. build is platform dependent! -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- JBoss dependency versions -->
        
        <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>

        <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
        <version.jboss.bom>8.2.1.Final</version.jboss.bom>
        <version.wildfly>9.0.0.Alpha1</version.wildfly>


        <!-- other plugin versions -->
        <version.compiler.plugin>3.1</version.compiler.plugin>
        <version.ear.plugin>2.10</version.ear.plugin>
        <version.ejb.plugin>2.3</version.ejb.plugin>
        <version.surefire.plugin>2.16</version.surefire.plugin>
        <version.war.plugin>2.5</version.war.plugin>

        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
    </properties>

    <dependencyManagement>
        <dependencies>

            <!-- Define the version of the EJB jar so that we don't need 
                to repeat ourselves in every module -->
            <dependency>
                <groupId>dave</groupId>
                <artifactId>dave-java-ee7-wildfly-full-ejb</artifactId>
                <version>${project.version}</version>
                <type>ejb</type>
            </dependency>
            
            <!-- Define the version of the WAR so that we don't need to repeat 
                ourselves in every module -->
            <dependency>
                <groupId>dave</groupId>
                <artifactId>dave-java-ee7-wildfly-full-web</artifactId>
                <version>${project.version}</version>
                <type>war</type>
                <scope>compile</scope>
            </dependency>

            <!-- JBoss distributes a complete set of Java EE 7 APIs including
                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or 
                a collection) of artifacts. We use this here so that we always get the correct 
                versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack
                (you can read this as the JBoss stack of the Java EE 7 APIs, with some extras
                tools for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
                stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
                from the Hibernate family of projects) -->
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- The WildFly plugin deploys your ear to a local JBoss
                    AS container -->
                <!-- Due to Maven's lack of intelligence with EARs we need 
                    to configure the wildfly maven plugin to skip deployment for all modules.
                    We then enable it specifically in the ear module. -->
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>${version.wildfly.maven.plugin}</version>
                    <inherited>true</inherited>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>


Download latest Wildfly AS here http://wildfly.org/downloads/

Deploy application to Wildfly using wildfly:deploy

mvn clean package wildfly:deploy


Access application using URL http://localhost:8080/dave-java-ee7-wildfly-full-web.


1 comment: