Maven - Pooky/java-enterprise-examples GitHub Wiki
Maven is build tool for java, which use repository and packing system like APT-GET in Linux distribution.
Very nice cheatsheet for maven: https://blogs.sap.com/2016/09/12/mvn/
- Link: https://maven.apache.org/
- Download: https://maven.apache.org/download.cgi
- Instal: https://maven.apache.org/install.html
Install Maven
Install is really simple.
- Download Maven
- Unzip archive into folder
- Add ./bin location to your %PATH% for Windows, Mac or Linux
Maven snippets
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
mvn install -Dmaven.test.skip=true
mvn clean install
mvn dependency:tree > dep.tree
Maven default folder structure
For maven project you have to use this specific structure, otherwise maven will not know, where are your files located and will not include them in result archive.
Folder location | Folder description |
---|---|
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/filters | Resource filter files |
src/main/webapp | Web application sources |
src/test/java | Test sources |
src/test/resources | Test resources |
src/test/filters | Test resource filter files |
src/it | Integration Tests (primarily for plugins) |
src/assembly | Assembly descriptors |
src/site | Site |
LICENSE.txt | Project's license |
NOTICE.txt | Notices and attributions required by libraries that the project depends on |
README.txt | Project's readme |
Maven test command
Maven can run test for you. You can use "mvn test" to run tests.
By default Maven uses the following naming conventions when looking for tests to run:
Folder: src/test/java
Test*
*Test
*TestCase
Your test class doesn't follow these conventions. You should rename it or configure Maven Surefire Plugin to use another pattern for test classes.
Maven scope
Maven dependency can be used in differend scope of build goals.
compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.