https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/
#解压文件
#tar -zxvf xxxx.gz
#修改profile文件 ,更改java版本使用
#vi /etc/profile
JAVA_HOME=/usr/local/jdk-9.0.4+11
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
export PATH JAVA_HOME CLASSPTH
#使用 source 使环境变量生效
source /etc/profile
# 验证java是否安装成功
java --version
#使用maven打包package,在项目文件夹执行
#maven clean package
<!--Pom配置 -->
<groupId>com.lepack</groupId>
<artifactId>manage</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.lepack.manage.ManageApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
使用java -jar命令启动项目
java -jar xxxx.jar --server.port=端口 --spring.profiles.active=环境
使用linux机器进行守护进程配置
# vi /etc/systemd/system/lepack-manage.service #文件服务地址
[Unit]
Description=lepackmanage
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/bin/bash -c "/usr/lepacksh/lepackmanage-start.sh -m standalone &"
User=root
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#配置启动sh文件
#!/bin/sh
export JAVA_HOME=/usr/local/jdk-9.0.4+11
export PATH=$JAVA_HOME/bin:$PATH
java -jar /usr/website/lepackmanage/manage-0.0.1-SNAPSHOT.jar --server.port=5007 --spring.profiles.active=test
echo $! > /etc/systemd/system/lepack.manage.service.pid
#配置停止sh文件
#!/bin/sh
PID=$(cat /etc/systemd/system/lepack.manage.service.pid)
kill -9 $PID
#记得给sh文件设置权限
# 查找文件在哪
find / -name lepackmanage-start.sh
chmod +x lepackmanage-start.sh
# systemctl enable lepack.manage.service
# systemctl start lepack.manage.service
# systemctl stop lepack.manage.service
#lsof -i:5007
kill -l pid #先使用这个,如果无法关闭再使用后面的
kill -9 PID #终止进程
#当出现错误信息/usr/local/jdk-9.0.4+11/lib/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory 的时候需要安装
#yum install libXp
#yum install libXt
#yum install libXtst
#安装完成之后如果出现错误信息
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.Font.initializeFont(Font.java:308)
at java.awt.Font.<init>(Font.java:344)
at com.google.code.kaptcha.util.Config.getTextProducerFonts(Config.java:102)
at com.google.code.kaptcha.text.impl.DefaultWordRenderer.renderWord(DefaultWordRenderer.java:35)
at com.google.code.kaptcha.impl.DefaultKaptcha.createImage(DefaultKaptcha.java:43)
at TestLinuxFont.main(TestLinuxFont.java:27)
如果出现以上出错,启动中加入java 参数
#-Djava.awt.headless=true