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

22. identifying excluding dependencies

mvn dependency:tree -Dverbose -Dincludes=log4j:log4j

i.e.:


[German@KDU foo-ejemplo (feature/ggonzalez/refactoring)]$ mvn dependency:tree -Dverbose -Dincludes=org.springframework:spring-core
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< cl.bar:foo-ejemplo >---------------
[INFO] Building foo-ejemplo 1.0.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ foo-ejemplo ---
[INFO] cl.bar:foo-ejemplo:war:1.0.0
[INFO] \- cl.bar.plataforma.common:foo-ejemplo-lib:jar:1.0.1:compile
[INFO]    +- org.springframework:spring-context:jar:4.2.1.RELEASE:compile
[INFO]    |  +- org.springframework:spring-aop:jar:4.2.1.RELEASE:compile
[INFO]    |  |  \- (org.springframework:spring-core:jar:4.2.1.RELEASE:compile - omitted for duplicate)
[INFO]    |  +- org.springframework:spring-beans:jar:4.2.1.RELEASE:compile
[INFO]    |  |  \- (org.springframework:spring-core:jar:4.2.1.RELEASE:compile - omitted for duplicate)
[INFO]    |  +- org.springframework:spring-core:jar:4.2.1.RELEASE:compile
[INFO]    |  \- org.springframework:spring-expression:jar:4.2.1.RELEASE:compile
[INFO]    |     \- (org.springframework:spring-core:jar:4.2.1.RELEASE:compile - omitted for duplicate)
[INFO]    \- org.springframework:spring-jdbc:jar:4.2.1.RELEASE:compile
[INFO]       +- (org.springframework:spring-core:jar:4.2.1.RELEASE:compile - omitted for duplicate)
[INFO]       \- org.springframework:spring-tx:jar:4.2.1.RELEASE:compile
[INFO]          \- (org.springframework:spring-core:jar:4.2.1.RELEASE:compile - omitted for duplicate)
 

23. Add local dependencies directly 

<dependency>
 <groupId>com.sample</groupId>
 <artifactId>sample</artifactId>
 <version>1.0</version>
 <scope>system</scope>
 <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>



        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <failOnMissingWebXml>true</failOnMissingWebXml>
                <webResources>
                    <resource>
                       <directory>${project.basedir}/lib</directory>
                       <targetPath>WEB-INF/lib</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>   
  


24. purge local
to clean up old dependencies (when someone change a library, but didn't upgrade the version, so we have a stale version)

mvn clean dependency:purge-local-repository 



 
25. maven options for -XX

export MAVEN_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/"


<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <argLine>-Xms512m -Xmx512m -XX:PermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=512m</argLine>
    </configuration>
  </plugin>
</plugins>


<properties>
<argLine>-Xms512m -Xmx512m -XX:PermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=512m</argLine>


26. sonar 

mvn sonar:sonar -Dsonar.host.url=http://127.0.0.1:9000 -Dsonar.login=d676f79d8ba83cdcf69f38f8471f0284ee242e09

27. javadoc 8 issues

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (attach-javadocs) on project foo-api-rest: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /Users/German/development/workspace-oepe-bch/foo-api-rest/src/main/java/cl/bar/plataformacomercial/foo/api/aop/HttpUtil.java:20: warning: no description for @param
[ERROR]      * @param request
[ERROR]        ^



This can be solved : https://devwebcl.blogspot.com/2016/01/jdk8-self-closing-element-not-allowed.html

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.