方法0. 使用 package打包
pom代码
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- spring-boot:run 中文乱码解决 -->
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<mainClass>com.iristar.center.ht.ApiServer</mainClass>
<!-- 生成的脚本文件的名称,比如start.sh,你也可以根据你的需要命名成其他名字 -->
</configuration>
</plugin>
<!--打包时跳过测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!--打包部署插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf8</encoding>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<id>Make Assembly</id>
<!-- 绑定到package生命周期阶段上 -->
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 生成linux, windows两种平台的执行脚本 -->
<platforms>
<platform>unix</platform>
<platform>windows</platform>
</platforms>
<!-- 包存放的根目录 -->
<assembleDirectory>${project.build.directory}/product</assembleDirectory>
<!-- 打包的jar,以及maven依赖的jar存放目录 -->
<repositoryName>lib</repositoryName>
<!-- lib目录中jar的存放规则,默认是${groupId}/${artifactId}的目录格式,flat表示直接把jar放到lib目录 -->
<!-- 可执行脚本的存放目录 -->
<binFolder>bin</binFolder>
<!-- 配置文件的存放目录 -->
<configurationDirectory>conf</configurationDirectory>
<!-- 拷贝配置文件到上面的目录中 -->
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<!-- 从哪里拷贝配置文件 (默认src/main/config) -->
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
<repositoryLayout>flat</repositoryLayout>
<encoding>UTF-8</encoding>
<logsDirectory>logs</logsDirectory>
<tempDirectory>tmp</tempDirectory>
<programs>
<program>
<!-- 启动类 -->
<mainClass>com.iristar.center.ht.ApiServer</mainClass>
<!-- 生成的脚本文件的名称,比如start.sh,你也可以根据你的需要命名成其他名字 -->
<name>ApiServer</name>
<jvmSettings>
<extraArguments>
<extraArgument>-server</extraArgument>
<extraArgument>-Xmx2G</extraArgument>
<extraArgument>-Xms2G</extraArgument>
<extraArgument>-Dfile.encoding=UTF-8</extraArgument>
</extraArguments>
</jvmSettings>
</program>
</programs>
</configuration>
</plugin>
<!--打包部署插件-->
</plugins>
<!--<resources>-->
<!--<resource>-->
<!--<directory>{project.basedir}/lib</directory>-->
<!--<targetPath>${project.build.directory}/product/lib</targetPath>-->
<!--<includes>-->
<!--<include>**/*</include>-->
<!--</includes>-->
<!--</resource>-->
<!--</resources>-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
命令如下
mvn clean package appassembler:assemble
注意事项:
问题(1):
windows下提示输入行太长
解决方法:
将原来的引入包的地方全部删掉,改为*
问题(2):
windows下提示找不到动态库
解决方法:
setx -m PATH "%PATH%;./"
linux下提示找不到动态库
解决方法:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./
方法1. 使用插件打包
pom代码
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<mainClass>com.iristar.TestApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- springboot自带build end-->
方法2. 使用 idea的Artifacts打包
运行
set path=%PATH%;dll-->
java -jar ./target/evalserver-1.0-SNAPSHOT.jar spring.config.addition-location=./application.properties
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./dll java -jar ./target/evalserver-1.0-SNAPSHOT.jar spring.config.addition-location=./application.properties
标签:java,plugin,--,maven,org,true,打包
From: https://www.cnblogs.com/hyhc8848/p/17052259.html