15 March 2016

Maven Cheat Sheet

Some reminder for Maven:

1. Use a different settings.xml
mvn --settings ~/.m2/YourOwnSettings.xml clean install
or
mvn -s ~/.m2/YourOwnSettings.xml clean install

2. Jboss tasks:
 mvn jboss-as:deploy
 mvn jboss-as:redeploy
 mvn jboss-as:undeploy

3. Eclipse Maven clean:
(retired)
mvn eclipse:eclipse
mvn eclipse:clean
mvn install

4. set java version:
<project>
 [...]
 <build>
 [...]
 <plugins>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>3.5.1</version>
 <configuration>
 <source>1.4</source>
 <target>1.4</target>
 </configuration>
 </plugin>
 </plugins>
 [...]
 </build>
 [...]
</project>

5. Missing Maven dependencies in Eclipse Project

   workaround to have an eclipse maven project


6. basic maven structure

src/main/java

 - src 
    - main 
          - java 
          - resources 
          - webapp 
     - test 
          - java 
          - resources 

- target

7. packaging:
<packaging>jar</packaging>

8. executing from maven:

add the following plugin to pom.xml:
<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>exec-maven-plugin</artifactId>
 <version>1.2.1</version>
 <configuration>
 <mainClass>com.myorganisationname.common.App</mainClass>
 </configuration>
<arguments> -Dlog4j.configurationFile=/tmp/log4j2.xml </arguments> <classpathScope>test</classpathScope> 
</plugin>

and run it with:

mvn exec:java

9. skipping test:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
      or
 
      mvn install -DskipTests
 

 
10. Multiple Module Projects
<packaging>pom</packaging>

<modules>
<module>guide-ide-eclipse-site</module>
<module>guide-ide-eclipse-core</module>
<module>guide-ide-eclipse-module1</module>
</modules>


Add the parent to the POMs of the new modules:

 <parent>
 <groupId>guide.ide.eclipse</groupId>
 <artifactId>guide-ide-eclipse</artifactId>
 <version>1.0-SNAPSHOT</version>
 </parent>


mvn install
mvn eclipse:eclipse

http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html


11. web archetype
mvn archetype:generate -DgroupId=cl.devweb -DartifactId=wls_log_retrieval -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
12. copy dependencies:
 mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR

13. tomcat
mvn tomcat7:deploy
mvn tomcat7:undeploy
mvn tomcat7:redeploy

14. verbose class
mvn test -DjvmArgs="-verbose:class"

15. web.xml-less
(servlet 3.0+)

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-war-plugin</artifactId>
 <version>2.6</version>
 <configuration>
  <failOnMissingWebXml>false</failOnMissingWebXml>
 </configuration>
</plugin> 
 
 
16. weblogic
 
              mvn com.oracle.weblogic:weblogic-maven-plugin:deploy

           mvn com.oracle.weblogic:weblogic-maven-plugin:undeploy


            <plugin>
                <groupId>com.oracle.weblogic</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>12.1.3-0-0</version>
                <configuration>
                    <adminurl>t3://127.0.0.1:7001</adminurl>
                    <user>weblogic</user>
                    <password>welcome1</password>
                    <upload>true</upload>
                    <action>deploy</action>
                    <remote>true</remote>
                    <verbose>true</verbose>
                    <source>target/${project.artifactId}.${project.packaging}</source>
                    <name>${project.artifactId}</name>
                    <targets>AdminServer</targets>
                </configuration>
            </plugin>
 
17. debug flag
mvn -X
or
mvn -e

18. update (when it does not find jar)
mvn -U package

19. dependencies
mvn dependency:tree
     -Dverbose

 
20. skip javadoc
-Dmaven.javadoc.skip=true
  
 
21. assigning different https protocol version :
(to avoid: Received fatal alert: protocol_version)

-Dhttps.protocols=TLSv1.2

No comments :

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.