Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Maven
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Syntax == Maven projects are configured using a [[#Project Object Model|Project Object Model (POM)]] in a <code>pom.xml</code> file. Example file: <syntaxhighlight lang="xml"> <project> <!-- model version is always 4.0.0 for Maven 2.x POMs --> <modelVersion>4.0.0</modelVersion> <!-- project coordinates, i.e. a group of values which uniquely identify this project --> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0</version> <!-- library dependencies --> <dependencies> <!-- The coordinates of a required library. The scope is 'test' to indicate the library is only used for running tests. --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.9.1</version> <scope>test</scope> </dependency> </dependencies> </project> </syntaxhighlight> This POM defines a unique identifier for the project (''coordinates'') and a single dependency on the [[JUnit]] library. However, that is already enough for building the project and running the [[Unit testing|unit tests]] associated with the project. Maven accomplishes this by embracing the idea of [[Convention over Configuration]], that is, Maven provides default values for the project's configuration. The directory structure of a normal [[Programming idiom|idiomatic]] Maven project has the following directory entries: [[file:Maven CoC.svg|thumb|A directory structure for a Java project auto-generated by Maven]] {| class="wikitable" |- ! Directory name ! Purpose |- | project home | Contains the <code>pom.xml</code> and all subdirectories. |- | <code>src/main/java</code> | Contains the deliverable Java source code for the project. |- | <code>src/main/resources</code> | Contains the deliverable resources for the project, such as property files. |- | <code>src/test/java</code> | Contains the testing Java sourcecode (JUnit or TestNG test cases, for example) for the project. |- | <code>src/test/resources</code> | Contains resources necessary for testing. |} The command <code>mvn package</code> will compile all the Java files, run any tests, and package the deliverable code and resources into <code>target/my-app-1.0.jar</code> (assuming the artifactId is my-app and the version is 1.0.) Using Maven, the user provides only configuration for the project, while the configurable plug-ins do the actual work of compiling the project, cleaning target directories, running unit tests, generating API documentation and so on. In general, users should not have to write plugins themselves. Contrast this with [[Apache Ant|Ant]] and [[make (software)|make]], in which one writes imperative procedures for doing the aforementioned tasks.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)