1.添加打包配置文件

1.1  assembly.xml

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/bin</directory>
<outputDirectory>/bin</outputDirectory>
<fileMode>0777</fileMode>
</fileSet>
<fileSet>
<directory>${project.build.directory}/conf</directory>
<outputDirectory>/conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
</assembly>

1.2  serverStatus.sh

#!/bin/sh
if [ ! -n "$JAVA_HOME" ]; then
export JAVA_HOME="/export/server/jdk1.8.0_141"
fi
APP_MAIN=${application.main.class}
PID= getPID(){
javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
if [ -n "$javaps" ]; then
PID=`echo $javaps | awk '{print $1}'`
else
PID=
fi
} getServerStatus(){
getPID
echo "================================================================================================================"
if [ $PID -ne ]; then
echo "$APP_MAIN is running(PID=$PID)"
echo "================================================================================================================"
else
echo "$APP_MAIN is not running"
echo "================================================================================================================"
fi
}
getServerStatus

1.3  shutdown.sh

#!/bin/sh
if [ ! -n "$JAVA_HOME" ]; then
export JAVA_HOME="/export/server/jdk1.8.0_141"
fi
APP_MAIN=${application.main.class}
PID= getPID(){
javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
if [ -n "$javaps" ]; then
PID=`echo $javaps | awk '{print $1}'`
else
PID=
fi
} shutdown(){
getPID
echo "================================================================================================================"
if [ $PID -ne ]; then
echo -n "Stopping $APP_MAIN(PID=$PID)..."
kill - $PID
if [ $? -eq ]; then
echo "[Success]"
echo "================================================================================================================"
else
echo "[Failed]"
echo "================================================================================================================"
fi
getPID
if [ $PID -ne ]; then
shutdown
fi
else
echo "$APP_MAIN is not running"
echo "================================================================================================================"
fi
} shutdown

1.4  startup.sh

#!/bin/sh
#-------------------------------------------------------------------------------------------------------------
#该脚本的使用方式为-->[sh startup.sh]
#该脚本可在服务器上的任意目录下执行,不会影响到日志的输出位置等
#-------------------------------------------------------------------------------------------------------------
if [ ! -n "$JAVA_HOME" ]; then
export JAVA_HOME="/export/server/jdk1.8.0_141"
fi #-------------------------------------------------------------------------------------------------------------
# 系统运行参数
#-------------------------------------------------------------------------------------------------------------
DIR=$(cd "$(dirname "$")"; pwd)
APP_HOME=${DIR}/..
CLASSPATH=$APP_HOME/conf
APP_LOG=${APP_HOME}/logs
APP_CONFIG=${APP_HOME}/conf/application.yml
APP_MAIN=${application.main.class} JAVA_OPTS="$JAVA_OPTS -server -Xms512m -Xmx512m -Xmn128m -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:MaxGCPauseMillis=850 -XX:+PrintGCDetails -Xloggc:$APP_LOG/gc.log -Dfile.encoding=UTF-8"
JAVA_OPTS="$JAVA_OPTS -DlogPath=$APP_LOG"
JAVA_OPTS="$JAVA_OPTS -Dconf.config=file:${APP_CONFIG}" echo "JAVA_HOME="$JAVA_HOME
echo "CLASSPATH="$CLASSPATH
echo "JAVA_OPTS="$JAVA_OPTS #-------------------------------------------------------------------------------------------------------------
# 程序开始
#-------------------------------------------------------------------------------------------------------------
for appJar in "$APP_HOME"/lib/*.jar;
do
CLASSPATH="$CLASSPATH":"$appJar"
done
PID=0 getPID(){
javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAIN`
if [ -n "$javaps" ]; then
PID=`echo $javaps | awk '{print $1}'`
else
PID=0
fi
} startup(){
getPID
echo "================================================================================================================"
if [ $PID -ne 0 ]; then
echo "$APP_MAIN already started(PID=$PID)"
echo "================================================================================================================"
else
echo -n "Starting $APP_MAIN"
if [ ! -d "$APP_LOG" ]; then
mkdir "$APP_LOG"
fi
nohup $JAVA_HOME/bin/java $JAVA_OPTS -classpath $CLASSPATH $APP_MAIN &
for i in $(seq 5)
do
sleep 0.8
echo -e ".\c"
done
getPID
if [ $PID -ne 0 ]; then
echo "(PID=$PID)...[Success]"
echo "================================================================================================================"
else
echo "[Failed]"
echo "================================================================================================================"
fi
fi
} startup

1.5  run.bat

title face-server
@echo off
rem ##############设置延迟环境变量扩充,即感叹号间的值不会因跳出循环而为空值。################
setlocal enabledelayedexpansion rem ###############java命令######################
set JAVA=%JAVA_HOME%\bin\java.exe rem ###############jvm参数######################
set OPTS=-Xms512M -Xmx512M -XX:+AggressiveOpts -XX:+UseParallelGC -XX:NewSize=64M rem ###############agent启动类参数######################
set serverMain=cn.micropattern.face.Application echo JAVA: %JAVA%
echo CLASSPATH: %CP%
echo OPTS: %OPTS%
java %OPTS% -cp "../lib/*;../conf" %serverMain%
PAUSE

1.6 pom.xml依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.test</groupId>
<artifactId>springboot-zip</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<application.main.class>com.test.Application</application.main.class>
<spring.boot.version>1.5.9.RELEASE</spring.boot.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring.boot.version}</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>${spring.boot.version}</version>
</dependency> </dependencies> <build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*.properties</include>
<include>*.yml</include>
<include>*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>scripts/*</exclude>
<exclude>*.properties</exclude>
<exclude>*.yml</exclude>
<exclude>*.xml</exclude>
</excludes>
</resource> <!-- 收集运行脚本 -->
<resource>
<directory>src/main/resources/scripts</directory>
<targetPath>${project.build.directory}/bin</targetPath>
<filtering>true</filtering>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</resource>
<!-- 收集配置文件 -->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}/conf</targetPath>
<filtering>true</filtering>
<includes>
<include>*.properties</include>
<include>*.yml</include>
<include>*.xml</include>
</includes>
</resource> <!-- 收集手动导入的jar包 -->
<resource>
<directory>lib</directory>
<targetPath>${project.build.directory}/lib</targetPath>
</resource>
</resources>
<plugins>
<!-- 1.用于编译的plugin -->
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-compiler-plugin</artifactId> -->
<!-- <version>3.1</version> -->
<!-- <configuration> -->
<!-- <fork>true</fork> -->
<!-- <source>1.8</source> -->
<!-- <target>1.8</target> -->
<!-- <encoding>UTF-8</encoding> -->
<!-- </configuration> -->
<!-- </plugin> --> <!-- 2.用于生成jar包的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<excludes>
<exclude>*.xml</exclude>
<exclude>*.yml</exclude>
<exclude>*.properties</exclude>
</excludes>
</configuration>
</plugin> <!-- 3.用于拷贝maven依赖(lib)的plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> <!-- 4.用于拷贝resource文件夹 的plugin --> <!-- 5.配置生成源代码jar的plugin[这里的源代码是指java文件,不是class文件] -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
<!-- 配置源代码jar文件的存放路径 -->
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin> <!-- 打包zip -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>dfrp-portal</id>
<configuration>
<archive>
<manifest>
<mainClass>${application.main.class}</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/scripts/assembly.xml</descriptor>
</descriptors>
<!-- 将依赖jar包都包含在目标jar中 -->
<!-- <descriptorRefs> -->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
<!-- </descriptorRefs> -->
<finalName>${project.name}-${version}</finalName>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

1.7controller层

@RestController
public class TestController {
@RequestMapping("/helloworld")
public String hello(String name) {
return "name" + name;
}
}

1.8Application启动类

@SpringBootApplication
public class Application { private static final Logger LOG = LoggerFactory.getLogger(Application.class); public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
LOG.info("**************** Startup Success ****************");
}
}

1.9application.yml

server:
port: 7070
session-timeout: 0
context-path: /

2.打包  install -Dmaven.test.skip=true

执行完命令后zip包在target文件路径下生成

3.linux启动服务

上传并解压zip包

启动成功

4.测试

测试成功

最新文章

  1. mybatis入门_一对多,多对多映射以及整合spring框架
  2. Android笔记——了解SDK,数据库sqlite的使用
  3. echosp 销量排行 新增实际价格
  4. EmguCV 轮廓分析函数汇总
  5. sass揭秘之变量(转载)
  6. eclipse ERROR: Unable to add module to the current project as it is not of ...
  7. Residual Networks &lt;2015 ICCV, ImageNet 图像分类Top1&gt;
  8. 利用有限自动机(finite automata)进行模式匹配
  9. Redis-主从配置了解
  10. ASP.NET Core MVC – 自定义 Tag Helpers
  11. 201521123082 《Java程序设计》第11周学习总结
  12. JS实现全选功能
  13. SQL 经典语句
  14. Python爬虫入门之Urllib库的基本使用
  15. 【aardio】回车换行符
  16. ie9 css文件大小限制
  17. mysql常用快速查询修改操作
  18. 从零开始学 Web 之 DOM(七)事件冒泡
  19. Linux学习之用户与root
  20. 用c++写一个数据库

热门文章

  1. 数据预处理 | 通过 Z-Score 方法判断异常值
  2. GearHost稳定免费美国全能空间测试主机100M容量
  3. numpy学习(三)
  4. [ZJOI2008] 骑士 - 基环树dp
  5. 获取table中CheckBox选中行的id
  6. Python基础教程-02
  7. django orm查询和后端缓存的使用
  8. 微信小程序中的左右联动
  9. CSS的快速入门
  10. X shell安装 以及使用