Featured Post

List Of Maven Commands

Creating Maven Projects

  • mvn archetype:create -DgroupId=com._3kbo -DartifactId=application (create a project for building a jar file )
  • mvn archetype:create -DgroupId=com._3kbo -DartifactId=webapplication -DarchetypeArtifactId=maven-archetype-webapp (create a web app project for building a war file)
  • mvn archetype:generate (Select the number of the desired archetype.)

Building, Testing, Packaging and Installing to the Repository

  • mvn clean            (cleans the project, i.e. delete the target directory)
  • mvn compile        (compiles the source code)
  • mvn test              (if required compiles the source code, then runs the unit tests)
  • mvn package       (compiles, tests then packages the jar or war file)
  • mvn clean install  (cleans the project, compiles, tests, packages and installs the jar or war file)
  • mvn install           (compiles, tests, packages and installs the jar or war file)
  • mvn -o install      (compiles, tests, packages and installs the jar or war file in offline mode)
  • mvn -Dmaven.test.skip package       (package without running the tests)
  • mvn -Dmaven.test.skip clean install  (clean and install without running tests)
  • mvn -o test         (test offline)

Unit Tests

  • mvn test –Dtest=AspectTest (run a specific test)
  • mvn test -Dtest=*ModelTest (run a subset of tests using regular expression. E.g. test all ModelTest classes)

Excluding log4j.properties from jar file

Move log4j.properties from src/main/resources to src/test/resources.
That way it gets picked up by the testResources for testing but excluded from the jar file.

Manually Install a file to the Repository

mvn install:install-file -DgroupId=com._3kbo -DartifactId=model -Dversion=1.0.0 -Dpackaging=jar -Dfile=new_file.jar

Set Java Build Version

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

Documentation

The mvn site command builds a useful dependency tree at target/site/dependencies.html.

  • mvn site (generate documentation in the target/site directory)
  • mvn javadoc:javadoc (generate javadoc in target/site/apidocs directory )
  • mvn help:active-profiles (lists the profiles currently active)
  • mvn help:effective-pom (displays the effective POM for the current build)
  • mvn help:effective-settings (displays the calculated settings for the project, given any profile enhancement and the inheritance of the global settings into the user-level settings.)
  • mvn help:describe (describes the attributes of a plugin)

For large projects mvn site can run out of memory. Use MAVEN_OPTS in the mvn or mvn.bat script to allocate additional memory, e.g:

MAVEN_OPTS="-Xmx512m -Xms256m -XX:MaxPermSize=128m"


Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...