用户工具

站点工具


linux:maven-jar-plugin

pom.xml

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<configuration>
		<archive>
			<manifest>
				<mainClass>com.sinosoft.app.Application</mainClass>
				<addClasspath>true</addClasspath>
			</manifest>
		</archive>
	</configuration>
</plugin>
#Class-Path: lib/plexus-utils-1.1.jar lib/commons-lang-2.1.jar
<classpathPrefix>lib/</classpathPrefix>
#Class-Path: lib/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar lib/commons-lang/commons-lang/2.1/commons-lang-2.1.jar
<classpathLayoutType>repository</classpathLayoutType>

init.sh ip

if [ $# -ne 1 ]; then
  echo "Usage: init.sh ip"
  exit 0
fi
service=`pwd|cut -d '_' -f 2`
ip=$1
if [ ${#ip} -le 3 ]; then
  ip=10.7.128.$1
fi
echo "init $service $ip"
mvn clean compile resources:resources jar:jar
mvn dependency:copy-dependencies -DoutputDirectory=target
rm -f target.tgz && tar zcvf target.tgz target
ssh tomcat@${ip} "cd /home/tomcat/code;rm -rf cmp_${service};rm -f target.tgz"
scp target.tgz tomcat@${ip}:/home/tomcat/code
scp start.sh tomcat@${ip}:/home/tomcat/code
ssh tomcat@${ip} "cd /home/tomcat/code;tar zxvf target.tgz;mv target cmp_${service};rm -f target.tgz;mv start.sh ${service}.sh"
rm -f target.tgz

start.sh service namespace

if [ $# -ne 2 ]; then
  echo "Usage: start.sh service namespace"
  exit 0
fi
service=$1
namespace=$2
nacos=10.7.128.11:8848,10.7.128.12:8848,10.7.128.13:8848
jar=cmp_${service}/cmp_${service}.jar
log=logs/cmp_${service}.log
#多个ControllerAdvice时需注意加载jar顺序,cp分隔符win=; linux=:
cp="cmp_${service}/cmp_${service}.jar"
for item in `ls cmp_${service}/*.jar`; do
  if [ -z $cp ]; then
    cp=$item
  else
    cp="$cp:$item"
  fi
done
#杀死正在运行的进程 ps -f -u dat指定用户
PID=`ps -ef|grep cmp_${service}.jar|grep -v 'grep'|awk '{print $2}'`
if [ -z "$PID" ]
then
    echo "没有服务正在运行。。。"
else
    echo "进程存在 杀死进程PID$PID"
    kill -9 $PID
fi
#暂停1秒
sleep 1
#启动服务
#nohup java -Dspring.cloud.nacos.config.server-addr=${nacos} -Dspring.cloud.nacos.config.namespace=service-namespace-${namespace} -Dspring.profiles.active=${namespace}  -jar ${jar} >> ${log} 2>&1 &
nohup java -Dspring.cloud.nacos.config.server-addr=${nacos} -Dspring.cloud.nacos.config.namespace=service-namespace-${namespace} -Dspring.profiles.active=${namespace}  -cp $cp com.sinosoft.app.Application >> /dev/null 2>&1 &
echo "启动中。。。"

deploy.sh namespace ip

if [ $# -ne 2 ]; then
  echo "Usage: deploy.sh namespace ip"
  exit 0
fi
service=`pwd|cut -d '_' -f 2`
namespace=$1
ip=10.7.128.$2
echo "deploy ${service} ${namespace} ${ip}"
mvn compile resources:resources jar:jar
scp target/cmp_${service}.jar tomcat@${ip}:/home/tomcat/code/cmp_${service}
ssh tomcat@${ip} "cd /home/tomcat/code;sh ${service}.sh ${service} ${namespace}"

deploys.sh

service=`pwd|cut -d '_' -f 2`
namespaceIps=(
    dev=24
    dat=29
)
mvn clean compile resources:resources jar:jar
for ((i=0; i<${#namespaceIps[@]}; ++i)); do
namespaceIp=${namespaceIps[i]}
namespace=`echo ${namespaceIp}|cut -d '=' -f 1`
ip=10.7.128.`echo ${namespaceIp}|cut -d '=' -f 2`
echo "deploy ${service} ${namespace} ${ip}"
scp target/cmp_${service}.jar tomcat@${ip}:/home/tomcat/code/cmp_${service}
ssh tomcat@${ip} "cd /home/tomcat/code;sh ${service}.sh ${service} ${namespace}"
done

auth.sh user ip

if [ $# -ne 2 ]; then
  echo "Usage: auth.sh user ip"
  exit 0
fi
user=$1
ip=$2
if [ ${#ip} -le 3 ]; then
  ip=10.7.128.$2
fi
echo "auth $user@$ip"
# ssh $user@$ip "mkdir ~/.ssh;touch ~/.ssh/authorized_keys;chmod 600 ~/.ssh/authorized_keys"
ssh $user@$ip "if [ ! -d ~/.ssh ]; then mkdir ~/.ssh; fi"
ssh $user@$ip "if [ ! -f ~/.ssh/authorized_keys ]; then touch ~/.ssh/authorized_keys;chmod 600 ~/.ssh/authorized_keys; fi"
ssh $user@$ip "curl http://t.xlongwei.com/windows/xlongwei.user.txt >> ~/.ssh/authorized_keys"
linux/maven-jar-plugin.txt · 最后更改: 2021/07/17 16:59 由 admin