Structure
Estimated time to read: 2 minutes
Folder Structure¶
By default, Maven looks for a /src/main/java
directory underneath a project folder.
It compiles code to a target
directory whilst referencing any defaults or overrides in the pom.xml file.
Example Folder Structure¶
/src/main/java¶
/src/main/java
is the directory is where Java code is stored. It also acts as the beginning of the package declaration. Maven will look here for Java code to compile
Other Languages¶
There are plugins for Maven that can be used to also build applications from other languages, code for these plugins to eventually build would be added to their relevant folder, ie /src/main/ruby
or /src/main/scala
Tests¶
/src/test/java
is used to store unit tests for the Java application.
target¶
The target
directory is where code, from the project, gets compiled to. This is also known as the Compilation Directory. It is also where unit tests are run from when a goal is processed.
- target
- classes <!-- /src/main/java builds -->
- maven-archiver <-- Packages -->
- maven-status
- test-classes <!-- Unit tests -->
- HelloWorld-1.0-SNAPSHOT.jar <-- Artefact -->
Goals¶
Goals within a basic application are straightforward:
clean
- Deletes the target directory and any generated sourcescompile
- Compile source code alongside stubs and skeletonspackage
- Runscompile
and runs unit tests dependant on the type that has been defined inside of the pom.xmlinstall
- Runs the package command and then copies the final package to the local repositorydeploy
- Runs theinstall
command and then deploys the package to a corporate / remote repository
Overriding Defaults¶
Defaults can be overwritten by modifying the build
element within the pom.xml file.
For example, to override the final name of the application, the following can be added under the build
element within the pom.xml; <finalName>foobar</finalName>
Local Repository Structure¶
Maven stores its local repository within the ~/.m2/repository
directory. This directory is stored in a similar place across various operating systems.
Maven stores its artefact information within the .m2
directory.
Packages are added to the local repository as <groupId>/<artifactId>/version
.