springboot jar文件打zip包运行linux环境中

时间:2021-09-12 00:06:26

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

springboot jar文件打zip包运行linux环境中

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

springboot jar文件打zip包运行linux环境中

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

springboot jar文件打zip包运行linux环境中

3.linux启动服务

上传并解压zip包

springboot jar文件打zip包运行linux环境中

springboot jar文件打zip包运行linux环境中

启动成功

4.测试

springboot jar文件打zip包运行linux环境中

测试成功

springboot jar文件打zip包运行linux环境中的更多相关文章

  1. Maven打包成Jar文件时依赖包的问题

    我们项目中使用到第三方的库文件,这些jar库文件并没有放到Maven*库上,导致我们需要在项目中自己配置使用.我们的两三个开发人员对Java都是很熟,因此在使用中遇到了一些问题,表现在:在本地中引入 ...

  2. mac终端命令加密压缩文件为zip包

    mac终端命令加密压缩文件为zip包,命令如下: zip -e ~/desktop/a.zip b.doc c.txt d.sql 注释:a.zip为加密后的文件 b.doc c.txt d.sql为 ...

  3. java批量下载文件为zip包

    批量下载文件为zip包的工具类 package com.meeno.trainsys.util; import javax.servlet.http.HttpServletRequest; impor ...

  4. 将jar文件加到Maven的local repository中

    对于Maven项目来说,日常使用的多数第三方java库文件都可以从Maven的Central Repository中自动下载,但是如果我们需要的jar文件不在Central Repository中,那 ...

  5. 她娇羞道&OpenCurlyDoubleQuote;不用这样细致认真的说啊~~”———详细图解在Linux环境中创建运行C程序

    她娇羞说,不用这样细致认真的说啊———详细图解在Linux环境中创建运行C程序“不,这是对学习的负责”我认真说到 叮叮叮,停车,让我们看看如何在Linux虚拟机环境中,创建运行C程序 详细图解在Lin ...

  6. &lbrack;软件测试&rsqb;Linux环境中简单清爽的Google Test (GTest)测试环境搭建(初级使用)

    本文将介绍单元测试工具google test(GTEST)在linux操作系统中测试环境的搭建方法.本文属于google test使用的基础教程.在linux中使用google test之前,需要对如 ...

  7. Linux环境中Openfire安装指南

    Linux环境中Openfire安装指南 安装环境: 安装软件:Openfire 4_1_0 http://download.igniterealtime.org/openfire/openfire_ ...

  8. 理解 Linux 网络栈(2):非虚拟化Linux 环境中的 Segmentation Offloading 技术

    本系列文章总结 Linux 网络栈,包括: (1)Linux 网络协议栈总结 (2)非虚拟化Linux环境中的网络分段卸载技术 GSO/TSO/UFO/LRO/GRO (3)QEMU/KVM + Vx ...

  9. linux环境中安装ftp服务

    需求说明: 今天项目中有一个新的需求,需要在linux环境中搭建一个ftp服务,在此记录下. 操作过程: 1.通过yum的方式安装ftp服务对应的软件包 [root@testvm01 ~]# yum ...

随机推荐

  1. &lbrack;bzoj2732&rsqb;&lbrack;HNOI2012&rsqb;射箭

    Description 沫沫最近在玩一个二维的射箭游戏,如下图所示,这个游戏中的$x$轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于$(0, ...

  2. Debugging D Program on Windows

    http://x64dbg.com/ http://www.ollydbg.de/version2.html

  3. sublime中侧边栏字体大小的设置

    sublime这个编辑器相当强大,但是它的侧边栏字体实在是太小了,实在是反人类的设计,幸好它给了我们修改的机会 第一步:下载PackageResourceViewer插件,通过PackageContr ...

  4. 【20160924】GOCVHelper综述

    GOCVHelper(GreenOpen Computer Version Helper )是我在这几年编写图像处理程序的过程中积累下来的函数库.主要是对Opencv的适当扩展和在实现Mfc程序时候的 ...

  5. python3 与 python2的 区别比较

    http://sebug.net/paper/books/dive-into-python3/porting-code-to-python-3-with-2to3.html

  6. sublime中配置Java 环境

    1.线安装jdk,并配置好环境变量2.创建批处理或Bash Shell脚本文件打开任意的文本编辑器,输入下面的内容,并保存为runJava.bat文件,然后把runJava.bat批处理文件移动到JD ...

  7. PHP全栈学习笔记6

    php能做什么,它是运行在服务器端的,web网站大部分数据都是存储在服务器上的,PHP就是用来处理这些存储在服务器的数据.跨平台,服务器可以是多种平台上的服务器,脚本语言,免费. wampserver ...

  8. Java 枚举 的学习

    在JDK5.0之后,引进了一种与C语言相通的枚举类型. 所谓枚举类型就是指含有一组具有固定值, 并且容量有限的数据集合. 例如,定义一个星期的枚举类型, 从周一到周日是具有固定大小和固定值的集合 pu ...

  9. 001&period;SSH配置文件

    一 ssh配置文件路径 1.1 ssh客户端配置文件: 路径:/etc/ssh/ssh_config 1.2 ssh服务端配置文件: 路径:/etc/ssh/sshd_config 二 服务器端常用配 ...

  10. Java基础之疑难知识点

    问题列表: 1. Java中子类中可以有与父类相同的属性名吗? 2. Java中子类继承了父类的私有属性及方法吗? 3. Java中抽象类到底能不能被实例化? 1. Java中子类中可以有与父类相同的 ...