Skip to content

Instantly share code, notes, and snippets.

@owen800q
Last active February 19, 2019 10:20
Show Gist options
  • Save owen800q/7d18243e1f4497ba5fb335fac3ca67a6 to your computer and use it in GitHub Desktop.
Save owen800q/7d18243e1f4497ba5fb335fac3ca67a6 to your computer and use it in GitHub Desktop.
Java package cheatsheet
Package a java project with maven plugin
pom.xml
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging> //here jar can be change to war depdends on what project is
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.kwancloud.app.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
-------------------------------------------------------------------------------------------------------------------
package spring boot application as a jar and war with maven spring boot plugin
If the spring boot application contains JSP file, then war is must nor jar. But if it contains only js css and html.jar is ok
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging> //here jar can be change to war depdends on what project is
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment