Maven Commands and Usage

Create your first project with Maven & Netbeans

Following Oracle 12.1.0.2 components were used

List JEE7 project templates for Maven repository:
[oracle@wls1 GIT]$ mvn archetype:generate | grep javaee7   
807: remote -> org.codehaus.mojo.archetypes:appclient-javaee7 (Archetype for an Application Client package using Java EE 7.)
812: remote -> org.codehaus.mojo.archetypes:ear-javaee7 (Archetype for EAR package using Java EE 7)
817: remote -> org.codehaus.mojo.archetypes:ejb-javaee7 (Archetype for an EJB package using Java EE 7.)
830: remote -> org.codehaus.mojo.archetypes:webapp-javaee7 (Archetype for a web application using Java EE 7.)
--> For building a Web Application select :  org.codehaus.mojo.archetypes:webapp-javaee7 

Create a new Maven project
[oracle@wls1 GIT] $ cd   /home/oracle/NetBeansProjects/GIT/
[oracle@wls1 GIT] $ mvn  -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=webapp-javaee7 \
       -DgroupId=com.hhu -DartifactId=WFMaven -Dversion=1.0 -Dpackage=com.hhu     \
       --batch-mode --update-snapshots archetype:generate
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
....
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/2.3/maven-archetype-plugin-2.3.jar (91 KB at 407.9 KB/sec)
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom ---
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-catalog/2.3/archetype-catalog-2.3.pom
....
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.21/plexus-utils-3.0.21.jar (240 KB at 403.8 KB/sec)
[INFO] Generating project in Batch mode
[INFO] Archetype [org.codehaus.mojo.archetypes:webapp-javaee7:1.1] found in catalog remote
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee7/1.1/webapp-javaee7-1.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee7/1.1/webapp-javaee7-1.1.jar (0 B at 0.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee7/1.1/webapp-javaee7-1.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee7/1.1/webapp-javaee7-1.1.pom (0 B at 0.0 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: webapp-javaee7:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.hhu
[INFO] Parameter: artifactId, Value: WFMaven
[INFO] Parameter: version, Value: 1.0
[INFO] Parameter: package, Value: com.hhu
[INFO] Parameter: packageInPathFormat, Value: com/hhu
[INFO] Parameter: package, Value: com.hhu
[INFO] Parameter: version, Value: 1.0
[INFO] Parameter: groupId, Value: com.hhu
[INFO] Parameter: artifactId, Value: WFMaven
[INFO] project created from Archetype in dir: /home/oracle/NetBeansProjects/GIT/WFMaven
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.821s
[INFO] Finished at: Sat Apr 18 10:10:54 CEST 2015
[INFO] Final Memory: 11M/42M
[INFO] ------------------------------------------------------------------------

Following Files were created 
Directories                    Files 
------------------------------ ------------------
WFMaven/                       pom.xml  src
WFMaven/src/main/java/com/hhu/ Empty directory
WFMaven/src/main/webapp/       index.html

Now Add JSF Framework and Wildfly Server to your project
Add Server        :  Properties -> Run -> Add Wildlfly Server 
Add JSF Framework :  Properties -> Framework -> Add JavaServer Faces 

Run the project a first time
$ firefox http://localhost:8180/WFMaven-1.0/
should print :  Hello from Facelets 

Replace  index.xhtml and  create java classes 
Replace index.xhmtl located in                  WFMaven/src/main/webapp 
Copy or create JAVA Source:  DriverBean.java to WFMaven/src/main/java/com/hhu

Sources, test results and Wildfly Intergration details  can be downloaded from : 
   http://www.hhutzler.de/blog/integrate-oracle-jdbc-driver-ucp-pool-ons-and-jsf-with-maven/

How to get Stack traces and Error message from a maven command ?

 
If needed always run your maven commands with -e or -X switch to get detailed Error stacks and Debug messages

 -X,--debug                             Produce execution debug output  
 -e,--errors                            Produce execution error messages

$ mvn test 
may return only a crypitcal info
2015-04-23 09:32:04,253 INFO  [stdout] (default task-16) -------------- driverTest2() running - Creating a Class not found Exception ---------------

Whereas  mvn -e provides add. info what is going wrong
$ mvn -e test
2015-04-23 09:13:19,985 INFO  [stdout] (default task-2) -------------- driverTest2() running - Creating a Class not found Exception ---------------
2015-04-23 09:13:19,987 INFO  [stdout] (default task-2) driverTest2() - return         : index
2015-04-23 09:13:19,988 INFO  [stdout] (default task-2) driverTest2() - JDBC INFO      : null
2015-04-23 09:13:19,988 INFO  [stdout] (default task-2) driverTest2() - Exception INFO : <pre>Error in checkDriver()</pre>
                                                                                         <pre>This_is_not_the_Oracle_JDBC_driver_class from [Module "deployment.testDriverBean.war:main" from Service Module Loader]</pre>
                                                                                         <pre>java.lang.ClassNotFoundException: This_is_not_the_Oracle_JDBC_driver_class from [Module "deployment.testDriverBean.war:main" from Service Module Loader]
2015-04-23 09:13:19,988 INFO  [stdout] (default task-2)     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
2015-04-23 09:13:19,988 INFO  [stdout] (default task-2)     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)
2015-04-23 09:13:19,988 INFO  [stdout] (default task-2)     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)
2015-04-23 09:13:19,989 INFO  [stdout] (default task-2)     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)
2015-04-23 09:13:19,989 INFO  [stdout] (default task-2)     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)
2015-04-23 09:13:19,989 INFO  [stdout] (default task-2)     at java.lang.Class.forName0(Native Method)
2015-04-23 09:13:19,989 INFO  [stdout] (default task-2)     at java.lang.Class.forName(Class.java:191)
2015-04-23 09:13:19,989 INFO  [stdout] (default task-2)     at com.hhu.DriverBean.checkDriver(DriverBean.java:163)

Managing application deployment with Wildfly Plugin

Sample:
     <build>    
        <plugins>
          ...
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.2.Final</version>
                <configuration>
                    <hostname>localhost</hostname>
                    <port>9990</port>
                    <username>administrator</username>
                    <password>helmut11</password>
                </configuration>    
            </plugin>
        </plugins>
    </build>

With above plugin you can easily manage application deployment by running 
$ mvn wildfly:deploy   [ -Dmaven.test.skip=true ]
$ mvn wildfly:redeploy [ -Dmaven.test.skip=true ]
$ mvn wildfly:undeploy 

Note: Use  -Dmaven.test.skip=true if you want to skip Maven Unit Testing

How to skip Maven Unit testing during application deployment ?

By default, when building project, Maven will run the entire unit tests automatically. 
If any of unit test is failed, it will force Maven to abort the building process.

See the following Maven UNIT test results :
$ mv test 
Tests run: 3, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 7.764 sec <<< FAILURE!

Results :
Failed tests:   
  poolTest(TestDriverBean): poolTest() does not found: RAC DB: BANKB - found: BANKA
  driverTest2(TestDriverBean): expected null, but was: 
    Error in checkDriver()
    This_is_not_the_Oracle_JDBC_driver_class from [Module "deployment.testDriverBean.war:main" from Service Module Loader]
    java.lang.ClassNotFoundException: This_is_not_the_Oracle_JDBC_driver_class from [Module "deployment.testDriverBean.war:main" from Service Module Loader]
Tests run: 3, Failures: 2, Errors: 0, Skipped: 0

-> Both errors are not fatal and you decided to deploy your project anyway. 

Solution : Deploy the project with  -Dmaven.test.skip=true
$ mvn clean
$ mvn wildfly:deploy -Dmaven.test.skip=true
$ firefox http://localhost:8180/WFMaven-1.0

 

Compile and Execute a JAVA class via Maven

Execute a JAVA Class
$ mvn compile exec:java  a -Dexec.mainClass="com.hhu.junittest.ThreadCounter"
[INFO] Scanning for projects...

Compile and execute as JAVA Class
$ mvn compile exec:java -Dexec.mainClass="com.hhu.junittest.ThreadCounter"
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building JUnitTestJava 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.6:copy (default) @ JUnitTestJava ---
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ JUnitTestJava ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ JUnitTestJava ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- exec-maven-plugin:1.3.2:java (default-cli) @ JUnitTestJava ---
[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
Hallo from ThreadCounter Class
Total 1,000 but was 1,000
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.229s
[INFO] Finished at: Mon May 25 15:45:16 CEST 2015
[INFO] Final Memory: 19M/46M
[INFO] ------------------------------------------------------------------------

 

Maven throws error java.net.NoRouteToHostException when connection to its repository

Apr 17, 2015 4:28:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: I/O exception (java.net.NoRouteToHostException) caught when connecting to the target host: No route to host
Apr 17, 2015 4:28:20 PM org.apache.maven.wagon.providers.http.httpclient.impl.client.DefaultRequestDirector tryConnect
INFO: Retrying connect

Workaround - Provide settings.xml :
[oracle@wls1 .m2]$ cat /home/oracle/.m2/settings.xml
<settings>
  <proxies>
   <proxy>
      <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>10.254.202.93</host>
      <port>80</port>
    </proxy>
  </proxies>
</settings>

Note you should verify your http proxy by running :
[oracle@wls1 UCP]$  telnet 10.254.202.93 80
Trying 10.254.202.93...
Connected to 10.254.202.93.
Escape character is '^]'.
[oracle@wls1 Desktop]$ ping 10.254.202.93
PING 10.254.202.93 (10.254.202.93) 56(84) bytes of data.
64 bytes from 10.254.202.93: icmp_seq=1 ttl=248 time=29.2 ms
64 bytes from 10.254.202.93: icmp_seq=2 ttl=248 time=29.0 ms

Search Maven repository

Maven Reference

Leave a Reply

Your email address will not be published. Required fields are marked *