Java Reference
In-Depth Information
This specifies a project called “my-se-project” (my standard-edition project) that will be
packaged into a JAR file; it depends on the JUnit 4.x framework for unit testing (see Avoid-
ing the Need for Debuggers with Unit Testing ) , but only needs it for compiling and running
tests. If I type mvn install in the directory with this POM, Maven will ensure that it has a
copy of the given version of JUnit (and anything that JUnit depends on), then compile
everything (setting CLASSPATH and other options for the compiler), run any and all unit
tests, and if they all pass, generate a JAR file for the program; it will then install it in my per-
sonal Maven repo (under ~/.m2/repository ) so that other Maven projects can depend on my
new project JAR file. Note that I haven't had to tell Maven where the source files live, nor
how to compile them—this is all handled by sensible defaults, based on a well-defined pro-
ject structure. The program source is expected to be found in src/main/java , and the tests in
src/test/java ; if it's a web application, the web root is expected to be in src/main/webapp by
default. Of course, you can override these.
Note that even the preceding config file does not have to be, and was not, written by hand;
Maven's “archteype generation rules” let it build the starting version of any of several hun-
dred types of projects. Here is how the file was created:
$ mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DgroupId=com.example -DartifactId=my-se-project
\[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/
maven-deploy-plugin/2.5/maven-deploy-plugin-2.5.pom
\[several dozen or hundred lines of downloading POM files and Jar files...]
\[INFO] Generating project in Interactive mode
\[INFO] Archetype [org.apache.maven.archetypes:maven-archetype-quickstart:1.1]
found in catalog remote
\[INFO] Using property: groupId = com.example
\[INFO] Using property: artifactId = my-se-project
Define value for property 'version': 1.0-SNAPSHOT: :
\[INFO] Using property: package = com.example
Confirm properties configuration:
groupId: com.example
artifactId: my-se-project
version: 1.0-SNAPSHOT
package: com.example
Y: : y
\[INFO] ------------------------------------------------------------------------
\[INFO] Using following parameters for creating project from Old (1.x) Archetype:
Search WWH ::




Custom Search