Maven
Useful Links¶
Basics¶
- Install:
- Settings file:
It contains user-specific configuration for authentication, repositories, and other information to customize the behavior of Maven.
- Maven Repo:
This directory contains your local Maven repository. When you download a dependency from a remote Maven repository, Maven stores a copy of the dependency in your local repository.
Directory Layout¶
Introduction to the standard directory layout
Without customization, source code is assumed to be in ${basedir}/src/main/java
and resources are assumed to be in ${basedir}/src/main/resources
.
Tests are assumed to be in ${basedir}/src/test
, and a project is assumed to produce a JAR file.
Maven assumes that you want the compile bytecode to ${basedir}/target/classes
and then create a distributable JAR file in ${basedir}/target
For WAR files, the /WEB-INF
directory contains a file named web.xml
which defines the structure of the web application.
See also Tomcat Deployment guide
Cheatsheet¶
- Bring up a menu of choices
mvn archetype:generate -DgroupId=com.dw -DartifactId=es-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
- Create a Java project
- Create a web project
mvn archetype:create -DgroupId=org.yourcompany.project -DartifactId=application -DarchetypeArtifactId=maven-archetype-webapp
- Clean project (will delete target directory)
- Validate project (validate the project is correct and all necessary information is available)
- Compile project (compile source code, classes stored in target/classes)
- Test project (run tests using a suitable unit testing framework)
- Package project (take the compiled code and package it in its distributable format, such as a JAR / WAR)
- Verify project (run any checks to verify the package is valid and meets quality criteria)
- Install project (install the package into the local repository, for use as a dependency in other projects locally)
- Deploy project (done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects)
- Deploy-file (can be used for deploying a external jar file to repository)
mvn deploy:deploy-file -Dfile=/path/to/jar/file -DrepositoryId=repos-server -Durl=http ://repos.company.o
You can run mvn site
and then find an index.html
file in target/site
that contains links to JavaDoc and a few reports about your source code.
POM files¶
Use the search engine at repository.sonatype.org to find dependencies by name and get the xml
necessary to paste into your pom.xml