pom.xml 加入插件
maven 打jar包插件,主要修改mainClass
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<!-- 添加index则不从mainfest中读取classpath,而是从Index.list中读取 -->
<!-- <index>true</index> -->
<manifest>
<mainClass>sjy.notion.boss.NotionBossApplication</mainClass>
<!-- to create a class path to your dependecies you have to fill true
in this field -->
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
<excludes>
<exclude>config/**</exclude>
</excludes>
</configuration>
</plugin>
maven自定义打包插件 用引入配置文件的方式
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!-- not append assembly id in release file name -->
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/build/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
打包的配置文件 package.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>package</id>
<formats>
<!-- 压缩包格式 -->
<format>tar.gz</format>
<format>dir</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<!-- 根目录的配置文件 放到包下根目录-->
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>application.yml</include>
<include>application-test.yml</include>
<include>application-pro.yml</include>
<include>logback-spring.xml</include>
<include>start.sh</include>
</includes>
</fileSet>
<!-- 项目jar包放到包下根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<!-- 项目依赖jar包放入lib目录 -->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
<excludes>
<exclude>${groupId}:${artifactId}</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
项目启动脚本start.sh
#!/bin/bash
nohup java -jar boss.jar --spring.config.location=application.yml > /dev/null 2>&1 &
echo $! > tpid
echo Start Success!
执行 mvn clean package 得到一个tar包
上传tar到服务器
tar -zxvf boss.tar.gz 解压
vi application.yml 修改配置
chmod +x start.sh 给执行权限
./start.sh 启动