注意:打包必须是用Lifecycle,而不是Plugins中的!!!
1.Lifecycle打包jar
2.上传Linux
3.进程查看杀死指定pid的进程
4.nohup运行shell
5.tail查看日志文件
1)修改pom.xml添加maven打包插件, 及其入口
<?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>org.example</groupId>
<artifactId>test_java</artifactId>
<version>1.0-SNAPSHOT</version>
<!--指定jdk版本-->
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<!-- 第1步: 最后打包出来要发布的jar包名字-->
<finalName>server</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<!--第2步: 配置程序启动入口-->
<archive>
<manifest>
<mainClass>org.example.TestFindAny</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
如下:
清理上次打包结果: Lifecycle下点击clean(这时发现整个target被删除)
打包:Lifecycle下点击package
打包后的jar: 在target下生成了在pom.xml中配置的名字和版本
2)scp命令将jar上传到linux服务器上的mnt目录下
λ scp nolockframework-disruptor.jar root@192.168.40.128:/mnt/
root@192.168.40.128's password:
nolockframework-disruptor.jar
3)查看当前jar包是否占用了端口,占用就结束掉
ps -ef | grep xxx.jar
kill xxxx端口
4)nohup方式重新运行 及其 shell脚本
nohup java -jar nolockframework-disruptor.jar > log.txt 2>&1&
查看运行的进程信息
启动jar的shell脚本
#!/bin/bash
PROJECTNAME=RangerALdapApi
pid=`ps -ef |grep $PROJECTNAME |grep -v "grep" |awk '{print $2}'`
if [ $pid ]; then
echo "$PROJECTNAME is running and pid=$pid"
else
echo "Start success to start $PROJECTNAME ...."
nohup java -jar RangerALdapApi-0.0.1-SNAPSHOT.jar >> catalina.out 2>&1 &
fi
停止jar的shell脚本
#!/bin/bash
PROJECTNAME=RangerALdapApi
pid=`ps -ef |grep $PROJECTNAME |grep -v "grep" |awk '{print $2}' `
if [ $pid ]; then
echo "$PROJECTNAME is running and pid=$pid"
kill -9 $pid
fi
if [[ $? -eq 0 ]];then
echo "sucess to stop $PROJECTNAME"
else
echo "fail to stop $PROJECTNAME"
fi
5)用宝塔放行8765端口让外网客户端可以连接上
不放行会报错连接不上
放行后,外网客户端就可以访问Netty服务器啦