Knowledge of Maven
is not required to use AppFuse because the tutorials explain how to use it. If you're interested in learning Maven in-depth, please download the book Better Builds with Maven
or Maven: The Definitive Guide
(zip
). Both books are free - the first requires registration, the second is available without registration.
For a brief introduction to Maven see Building Web Applications with Maven 2
or The Maven 2 POM demystified
. Other articles are available from the Articles on Maven
page.
See Maven Plugins for information on plugins used in AppFuse.
Below is a list of commonly-used helpful Maven commands.
| Command |
Description |
| mvn clean |
Deletes all files in target directory or directories (for multi-module projects) |
| mvn jetty:run-war |
Packages and deploys your application to Jetty, reachable at http://localhost:8080 |
| mvn -Dcargo.wait=true |
Packages and deploys your application to active Cargo profile (Tomcat 5.5.x by default), reachable at http://localhost:8080/yourapp-version |
| mvn test |
Runs all tests in src/test/java. Use "-Dtest=ClassName" (not fully-qualified) to run individual tests. |
| |
Use -Dsurefire.useFile=false if you want to see test failures in your console (like Ant) and -Dmaven.surefire.debug if you want to open a debugger on port 5005 w/ suspend=y. |
| mvn package |
Creates a WAR or JAR depending on your project type |
| mvn integration-test |
Runs UI tests in Tomcat using Cargo |
| mvn install |
Installs generated artifacts in your local repository |
| mvn site |
Creates project site and reports |
| mvn -U |
Checks for updated plugins and downloads if they exist |
| mvn -o |
Work offline |
| mvn --help |
See full list of optional commands |
Ant vs. Maven
If you used AppFuse 1.x in the past and have taken the time to memorize its useful Ant commands
, the following table should help you convert to using Maven.
| Ant command |
Maven command |
Description |
| ant setup-db |
mvn hibernate3:hbm2ddl dbunit:operation |
Creates and populates your database |
| ant test-all |
mvn integration-test |
Runs unit and integration tests |
| ant clean |
mvn clean |
Deletes the target directory |
| ant compile |
mvn compile |
Compiles all source files |
| ant war |
mvn package |
Creates a WAR file |
| ant deploy |
mvn jetty:run-war |
Deploys a WAR to embedded instance of Jetty and starts it |
| ant test-dao |
mvn test -Dtest=*DaoTest |
Runs all DAO tests |
| ant test-service |
mvn test -Dtest=*ManagerTest |
Runs all Manager tests |
Installing a local Maven Repository
If you're using Maven 2 in your organization on multiple projects, it's often a good idea to setup a local Maven repository on your intranet. There's a few different strategies for doing this:
Troubleshooting and other Tips
The tips below are copied from Mule's Tips and Tricks with Maven 2.x
. Thanks guys. 
 | OutOfMemoryError
If you are getting OutOfMemoryError exceptions when attempting a full build of Mule you may try increasing the max heap and the PermGen space sizes. Either export a MAVEN_OPTS variable in your shell or add it to the original mvn script. The following settings were confirmed working fine with Mule:
MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m
|
 | Offline option
If you know your downloads are up-to-date, you can use the offline option which may speed up your build considerably depending on network latency:
|
 | Debug option
Transitive dependencies in m2 are both a blessing and a curse. The debug option is especially helpful when you find yourself in "classloader hell" (conflicting library versions or unwanted libraries are in your classpath). Among other things, it prints out the effective classpath in a tree format which makes it easy to see where each libraries is coming from.
|
 | Non-recursive option
Executing a Maven goal for a module will by default execute the goal for any modules below it in the hierarchy. If you specifically wish to run the goal for this module only (and not its children) you can use the non-recursive option.
|
 | Debugging test failures
Surefire, which is the default Maven test runner now, outputs all reports as a set of xml and text files. Any test failure details and stacktraces end up in those files, and not the console. The output can be redirected to the console temporarily by adding the following option
mvn -Dsurefire.useFile=false
This option will skip creating the text report, but the xml one will still be available for transformation by tools. |