Java - Maven
common commands
./mvnw -s .mvn/settings.xml clean test
./mvnw -s .mvn/settings.xml clean test -Dtest=com.lgh.UtilTest
./mvnw -s .mvn/settings.xml clean spring-boot:run
./mvnw -s .mvn/settings.xml clean package
./mvnw -s .mvn/settings.xml clean package -Dmaven.test.skip=true
./mvnw -s .mvn/settings.xml clean install
./mvnw -s .mvn/settings.xml clean deploy
Initialize project
create jar project myapp (a folder named myapp will be created)
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
create war project myweb (a folder named myweb will be created)
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=myweb -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp
after that, add the following lines to the pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<finalName>myweb</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<debug>false</debug>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>net.johnsonlau.java.sandbox.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Copy dependent libs to folder
mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/folder
Runing the application
mvn exec:java -Dexec.mainClass=net.johnsonlau.java.sandbox.App
or
java -jar target/java-sandbox.jar
or
java -cp target/classes:target/dependency/* net.johnsonlau.java.sandbox.App
Install jar to local repository
mvn install:install-file -DgroupId=org.elasticsearch.plugin -DartifactId=shield -Dversion=2.3.2 -Dpackaging=jar -Dfile=lib/shield-2.3.2.jar