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:
- Artifactory
- a Maven2 proxy repository based on JSR-170. Started with maven-proxy's codebase. See Setting up a Maven repository with Artifactory
for installation instructions. - Dead Simple Maven Proxy
- DSMP is a proxy. It can be used as a repository server but it's main purposs it to act as a filter when Maven accesses the internet. If you need a repository server, use Archiva. - Maven Archiva
- still under development. - Maven Proxy
- See Sanjiv's blog entry titled Using maven-proxy to setup an internal maven repository
for more information. - Proximity
- Proximity functions somewhere between http-proxy and proactive-mirror. One of its primary uses is as Java web application to serve as a Maven proxy on your company's intranet.
本文介绍如何使用Maven进行Web应用开发,包括常见Maven命令的使用、从Ant迁移到Maven的方法以及搭建本地Maven仓库的策略。无论您是否熟悉Maven,都能通过本文快速上手。
8484

被折叠的 条评论
为什么被折叠?



