maven 打包时依赖 jar 包分离, pom 添加

<!--依赖复制到lib-->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>
                    ${project.build.directory}/lib
                </outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

正常 maven 打包之后会在 target 下添加 lib, 里面是所有依赖, jar 包只有该项目的代码,java项目www.1b23.com  如果有静态文件(包括 jsp)可放入 static 目录

服务器脚本:

//java项目www.fhadmin.org
#! /bin/sh

MAIN_JAR_NAME="xxx-0.0.1-SNAPSHOT.jar"
MAIN_CLASS="com.dahua.xxxApplication"

PROJECT_HOME=$(cd `dirname $0`; pwd)

cd ${PROJECT_HOME}

PROJECT_LIB=${PROJECT_HOME}/code/lib

PROJECT_CONF=${PROJECT_HOME}/code/conf
PROJECT_JAR=${PROJECT_HOME}/${MAIN_JAR_NAME}

CLASSPATH=.:${PROJECT_CONF}:${PROJECT_JAR}
for i in ${PROJECT_LIB}/*.jar ; do
  CLASSPATH=${CLASSPATH}:${i}
done

DFlag=${MAIN_JAR_NAME}_${MAIN_CLASS}
CUR_SERVICE=`ps -ef | grep ${DFlag} | grep -v "grep" | awk '{print $2}'`
for PID in ${CUR_SERVICE}
do
   kill -9 ${PID}
   echo "结束进程: ${PID}"
done

nohup java -server -DFlag=${DFlag} -Dfile.encoding=UTF-8 -cp ${CLASSPATH} ${MAIN_CLASS} $@ 1>>nohup.out 2>&1 &