java maven项目常用 build配置及启动脚本

来源:互联网 发布:php网络验证源码 编辑:程序博客网 时间:2024/04/30 09:36
<build>    <finalName>${project.artifactId}</finalName>        <resources>                <resource>                <directory>src/main/resources</directory>                <!-- 资源根目录排除各环境的配置,使用单独的资源目录来指定 -->                <excludes>                    <exclude>dev/*</exclude>                    <exclude>test/*</exclude>                    <exclude>product/*</exclude>                </excludes>            </resource>            <resource>                <directory>src/main/resources/${profiles.active}</directory>            </resource>        </resources>        <plugins>            <!-- jar 打包 -->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-jar-plugin</artifactId>                <version>2.4</version>                <configuration>                    <excludes>                        <exclude>**/*.properties</exclude>                        <exclude>**/*.xml</exclude>                        <exclude>**/*.xsd</exclude>                    </excludes>                    <outputDirectory>target/${project.name}/lib/</outputDirectory>                </configuration>            </plugin>            <!-- copy 依赖包 -->            <plugin>               <groupId>org.apache.maven.plugins</groupId>                    <artifactId>maven-dependency-plugin</artifactId>                    <version>2.10</version>                    <executions>                      <execution>                        <id>copy-dependencies</id>                        <phase>package</phase>                        <goals>                          <goal>copy-dependencies</goal>                        </goals>                        <configuration>                          <outputDirectory>${basedir}/target/${project.name}/lib/</outputDirectory>                          <overWriteReleases>false</overWriteReleases>                          <overWriteSnapshots>false</overWriteSnapshots>                          <overWriteIfNewer>true</overWriteIfNewer>                          <excludeScope>system</excludeScope>                        </configuration>                      </execution>                    </executions>            </plugin>            <plugin>                <artifactId>maven-resources-plugin</artifactId>                <version>2.7</version>                <!-- 不同环境的资源文件-->                <executions>                    <execution>                        <id>copy-resources</id>                        <phase>package</phase>                        <goals>                            <goal>copy-resources</goal>                        </goals>                        <configuration>                            <outputDirectory>target/${project.name}/conf</outputDirectory>                            <resources>                                <resource>                                    <directory>src/main/resources</directory>                                    <excludes>                                        <exclude>dev/*</exclude>                                        <exclude>test/*</exclude>                                        <exclude>product/*</exclude>                                    </excludes>                                </resource>                                <resource>                                    <directory>src/main/resources/${profiles.active}</directory>                                </resource>                            </resources>                        </configuration>                    </execution>                    <!-- 执行Shell 脚 本-->                    <execution>                        <id>copy-script</id>                        <phase>package</phase>                        <goals>                            <goal>copy-resources</goal>                        </goals>                        <configuration>                            <outputDirectory>target/${project.name}/</outputDirectory>                            <resources>                                <resource>                                    <directory>src/main/scripts/</directory>                                    <filtering>true</filtering>                                </resource>                            </resources>                        </configuration>                    </execution>                </executions>            </plugin>        </plugins>    </build>

daemon.sh

#!/bin/shBASE_DIR=$(cd "$(dirname "$0")"; pwd)/cd $BASE_DIRGLOBAL_ID=${BASE_DIR}CUR_APPID=tracker-serverAPP_VERSION=1.0APP_NAME=com.XXX.XXXX.parser.TrackerServer  --修改成你的启动类APP_PARA=LOGFILE="stdout.log"LIBS=./libPUB_LIB=""for jar in `find $LIBS -name "*.jar"`do      PUB_LIB="$PUB_LIB:""$jar"doneJAVACLASSPATH=./conf/:.:$PUB_LIBJAVABIN=javacurDate=`date '+%G%m%d'`curTime=`date '+%H%M%S'`# Functions for all the parametersfunction displayHelp(){       echo '  '        echo ' Please Attach a parameter when run this shell   '        echo ' Parameters:'        echo '      -start  : Start Application in Service Mode(Log to File)'        echo '      -stop   : Stop The Application'        echo '      -restart: Restart The Application'        echo '      -status : Display Running Status of The Application'        echo '      -version: Display current App Version'        echo '  '        echo " Version: $APP_VERSION"        echo '  '}function displayAppStatus(){   echo "  "      echo "Current App["$CUR_APPID"] at [${BASE_DIR}] Status: "   echo " "   ps -ef |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME   echo ""}function stopApp(){  echo "trying stop app $CUR_APPID ......................"  #echo '########### stop by user #####' >> ./logs/$LOGFILE.$(date +%F)  PID=`/bin/ps -ef | grep -v .sh |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME | grep -v grep |awk '{print $2}'` #  PID=`/bin/ps -ef | grep -v .sh |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME | grep -v console |grep -v grep |awk '{print $2}'`  if [ ! -z "${PID}" ]; then    kill -15 $PID  fi    sleep 1  PID=`/bin/ps -ef | grep -v .sh |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME |grep -v console |grep -v grep |awk '{print $2}'`  if [ ! -z "${PID}" ]; then    kill -9 $PID    kill -9 `/bin/ps -ef | grep -v .sh |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME |grep -v console |grep -v grep |awk '{print $2}'`    sleep 1  fi  echo "success stop app $CUR_APPID at [${GLOBAL_ID}] !!!!!!!!!!!!!!!!!!!"}function startApp(){  echo "trying start app $CUR_APPID ......................"  mv ./logs/$LOGFILE.$(date +%F) ./logs/$curDate\_$curTime\_$CUR_APPID.log  JVM_PARAM="        -server        -Xmx256M        -Xms256M        -Xmn128M        -XX:PermSize=56M        -XX:MaxPermSize=128M        -XX:GCTimeRatio=19        -XX:+ClassUnloading         -XX:+UseConcMarkSweepGC        -Xloggc:log/gc.log    "#  $JAVABIN -DAPPID=$CUR_APPID -DGID=$GLOBAL_ID $JVM_PARAM -classpath $JAVACLASSPATH $APPJAVA_ADDPRO  $APP_NAME $APP_PARA >&1 \ | /usr/local/sbin/cronolog "$BASE_DIR"/logs/$LOGFILE.%Y-%m-%d >> /dev/null &  $JAVABIN -DAPPID=$CUR_APPID -DGID=$GLOBAL_ID $JVM_PARAM -classpath $JAVACLASSPATH $APPJAVA_ADDPRO  $APP_NAME $APP_PARA >>/dev/null &  echo "success start app $CUR_APPID at [${GLOBAL_ID}] !!!!!!!!!!!!!!!!!!!"  ps -ef |grep $GLOBAL_ID | grep $CUR_APPID | grep $APP_NAME > pid  displayAppStatus}function restartApp(){    stopApp    sleep 1    startApp    exit}if [ $# -eq 0 ]; then    displayHelp    exitfi# Shell Controlif [ $1 = "-start" ]; then    stopApp     sleep 1    startApp    sleep 2    displayAppStatus    exitfiif [ $1 = "-stop" ]; then    stopApp    sleep 2    displayAppStatus    exitfiif [ $1 = "-status" ]; then    displayAppStatus    exitfiif [ $1 = "-restart" ]; then    restartApp    exitfiif [ $1 = "-version" ]; then    echo "       version: $APP_VERSION"    exitfi

restart.sh

#!/bin/shBASE_DIR=$(cd "$(dirname "$0")"; pwd)/cd $BASE_DIRsh daemon.sh -restart

start.sh

#!/bin/shBASE_DIR=$(cd "$(dirname "$0")"; pwd)/cd $BASE_DIRsh daemon.sh -start

stop.sh

#!/bin/shBASE_DIR=$(cd "$(dirname "$0")"; pwd)/cd $BASE_DIRsh daemon.sh -stop
0 0
原创粉丝点击