You can create project by maven. But basically, we don’t prefer to do it. We always use Eclipse/IntelliJ to create maven project.
After creating project by maven project template in IntelliJ, we got below folder.
MyWebApp
|–.idea
|–src
|—-main
|—-resources
|–test
|–pom.xml
By default, we only have one setting named as “POM.xml”. It includes all core information related to project building/dependencies/basic artefact information.
Initialize pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myApp</groupId>
<artifactId>myApp</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Based on these initial settings, you can install package through maven clean install command.
Maven Build Process:
–validate: validate the project is correct and all necessary information is available
–compile: compile the source code of the project
–test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
–package: take the compiled code and package it in its distributable format, such as a JAR.
–integration-test: process and deploy the package if necessary into an environment where integration tests can be run
–verify: run any checks to verify the package is valid and meets quality criteria
–install: install the package into the local repository, for use as a dependency in other projects locally
–deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
However, we want to add some dependencies and repositories. Given that, we need to modify pom.xml & add another setting file named as “Settings.xml”.
There are two settings.
POM.xml:
(1) We want to add JUNIT dependency. Given that, we add below settings.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
(2) We want to add one plug-in when building projects, so that we add these settings.
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<webApp>
<contextPath>/MyWebApp</contextPath>
</webApp>
<httpConnector>
<port>80</port>
</httpConnector>
</configuration>
</plugin>
</plugins>
</build>
Settings.xml: This configuration manage the global level configuration information for all maven projects.
These include values such as the local repository location, alternate remote repository servers, and authentication information
We define local repository & remote repository.
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/Users/kangxiwei/maven</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<profiles>
<profile>
<id>profile-default</id>
<repositories>
<repository>
<id>repo-mirror</id>
<url>http://maven.net.cn/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>plugin-repo-mirror</id>
<url>http://maven.net.cn/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Related links:
Maven in 5 Minutes
Maven Getting Started
Maven Settings.xml