美文网首页
assembly :实现依赖、配置分离

assembly :实现依赖、配置分离

作者: ClineChen | 来源:发表于2018-05-09 10:19 被阅读10次

    maven 配置

    <build>
        <finalName>demo</finalName>
        <plugins>
            <plugin>
                <group>org.apache.maven.plugins</group>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                     <source>${java.version}</source>
                     <target>${java.version}</target>
                     <compilerArgument>-Xlint:all</compilerArgument>
                     <showWarnings>true</showWarnings>
                     <showDeprecation>true</showDeprecation>
                     <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
    
            <plugin>
                <group>org.apache.maven.plugins</group>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                         <manifest>
                             <mainClass>com.example.demo.Application</mainClass>
                             <addClasspath>true</addClasspath>
                             <classpathPrefix>lib/</classpathPrefix>
                         </manifest>
                         <manifestEntries>
                             <Class-Path>./</Class-Path>
                         </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                   <appendAssemblyId>false</appendAssemblyId>
                   <descriptors>
                      <descriptor>src/main/resources/config/package.xml</descriptor>
                   </descriptors>              
                </configuration>
                <executions>
                   <execution>
                       <id>make-assembly</id>
                     <phase>package</phase>
                     <goals>
                         <goals>single</goals>
                     </goals>
                   </execution>
                </executions>
            </plugin>
        </pligins>
    </build>
    

    assembly配置: package.xml

    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
        <id>package</id>
        <formats>
            <format>tar.gz</format>
        </formats>
        <includeBaseDirectory>true</includeBaseDirectory>
        <fileSets>
            <fileSet>
                <directory>bin</directory>
                <outputDirectory>./</outputDirectory>
            </fileSet>
            <fileSet>
                <directory>src/main/resources/config</directory>
                <outputDirectory>./config</outputDirectory>
            </fileSet>
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>./</outputDirectory>
                <includes>
                    <include>*.jar</include>
                </includes >
            </fileSet>
        </fileSets>
        <dependencySets>
            <dependencySet>
                <outputDirectory>lib</outputDirectory>
                <scope>runtime</scope>
                <excludes>
                    <exclude>${groupId}:${artiffactId}</exclude>
                </excludes>
            </dependencySet>
        </dependencySets>
    </assembly>
    

    启动脚本

    #! /bin/sh
    
    
    #jar 名称
    app=demo
    #自定义java地址,如果没有取系统环境变量内定义的java
    javaPath="/mnt/osservice/jre_1.7/bin/java" 
    java=java 
    pidfile=$app".pid" 
    rm -f $pidfile touch $pidfile 
    echo "start $app service" 
    ulimit -c unlimited 
    ulimit -n 10240
    #set java path
    #export PATH=$PATH:/mnt/osservice/jre_1.7/bin/
    # if exist javaPath then set java to this javaPath
    if [ -n $javaPath ]; then
       echo "set javaPath: $javaPath " 
       java=$javaPath 
    fi
    nohup $java -server -Djava.ext.dirs=lib -Xms512m -Xmx512m -Xmn384m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -jar $app.jar  > start_log.log 2>&1 & sleep 1 
    running=`ps -p $! | grep -v "PID TTY" | wc -l`
    if [ $running -gt 0 ];then 
       echo $! > $pidfile 
       echo "$app started..., pid=$!" 
    else 
       echo "$app failed to start." 
       exit 1 
    fi
    

    停止脚本

    #!/bin/bash
    
    #jar 名称
    app=demo
    pid=ps x|grep $app |grep -v "get $app Pid" |grep -v grep |awk '{print $1}' 
    echo "$app stop pid: $pid" 
    echo $pid |while read p 
    do 
    if [ "X$p" = "X" ] then 
        echo "$app was not running." 
    else 
        echo "kill -9 $p" 
        kill -9 $p 2>/dev/null 
        echo "$app stop success" 
    fi 
    done
    

    相关文章

      网友评论

          本文标题:assembly :实现依赖、配置分离

          本文链接:https://www.haomeiwen.com/subject/rfogwxtx.html