Maven step by step
Both Windows and Linux can use the same steps here.
Download maven
http://apache.arvixe.com/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.zip
Extract it to C:\maven\apache-maven-3.3.3
Set an environment variable MAVEN_HOME to C:\maven\apache-maven-3.3.3
Add the %MAVEN_HOME%\bin to PATH. Linux uses this $MAVEN_HOME/bin
Set the Maven Repo directory
Open MAVEN_HOME\conf\settings.xml
Find the "localRepository", uncomment and edit it:
<localRepository>C:/maven/maven_repo</localRepository>
If you use proxy to access internet, find "proxy", uncomment and edit it:
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
Generate a new Java project by Maven
mvn -B archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.example.app \
-DartifactId=my-app
Build and Run the project
mvn package
java -cp target/my-app-1.0-SNAPSHOT.jar com.example.app.App
make the Maven project available in Eclipse
mvn eclipse:eclipse
Adding the Report into project documents:
Open the pom.xml and add this:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
<link>http://commons.apache.org/lang/api</link>
<link>http://java.sun.com/j2se/1.7.0/docs/api</link>
</links>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
</plugins>
</reporting>
Run this to generate project document
# mvn site
Open this in Web browser
# target/site/index.html
Make JAR executor file for project
Add this into pom.xml
<build> <plugins> <!-- Make this jar executable --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <!-- Jar file entry point --> <mainClass>com.example.app.App</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build>
Run it
# mvn install
# java -jar target/my-app-1.0-SNAPSHOT.jar
Run the main method inside a maven phase
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.app.App</mainClass>
<!-- <arguments> <argument>arg0</argument> <argument>arg1</argument>
</arguments>
-->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run the test phase and the method will also execute too.
# mvn test