Maven Basics
Maven is a build system for Java, it automaticly manages dependencies, your build process, jar file creation, the creation of javadocs and allows you to write custom extentions and templates. It uses a file called pom.xml to describe how your project will be built. This guide talks you though Maven concepts to get you started.
Creating a maven project
mvn archetype:generate
# Everything we build goes in target, let git ignore it.
echo "target/" >> .gitignore
Building a maven project
mvn clean package
Build Lifecycle
- Validate
- compile
- test
- package
- verify
- install
- deploy
Useful properties
Put these in your pom.xml properties section.
- project.build.sourceEncoding -> encoding for source file
- maven.compiler.source -> Java language spec your source uses (1.5 by default, 1.8 = Java 8)
- maven.compiler.target -> Java language spec your compiled files should be (1.5 by default, usually should match the above)
Standard Layout
- src/main/java - Java Sources
- src/main/resources - Java Resources (non-java files which should be in your JAR)
- src/test/java - Java test sources (JUnit tests, etc...)
- src/test/resources - Java resources for running tests (dummy files, data for test cases, etc...)
- LICENCE.txt - Your licence
- NOTICE.txt - Required attribution notices for libraries you use
- README.txt - Your project's readme
- pom.xml - The data describing your build process