用assembly把maven工程打成tar包

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

maven使用三板斧--打tar.gz包。

1. 先看一个maven工程结构

用assembly把maven工程打成tar包_第1张图片

2. pom.xml配置


    
        
            src/main/java
            true
        
        
            src/main/resources
            true
            
                **/*.xml
                **/*.properties
                **/*.cfg
            
            
        
    
    
        
            org.apache.maven.plugins
            maven-jar-plugin
            
                
                    **/*.xml
                    **/*.properties
                
            
            
                
                    make-assembly
                    package
                    
                        jar
                    
                
            
        
        
            maven-assembly-plugin
            
                
                    src/main/assembly/src.xml
                
            
            
                
                    make-assembly
                    package
                    
                        single
                    
                
            
        
    

3. 打包配置 src/main/assembly/src.xml


    bin
    
        tar.gz
    
    false
    
        
            true
            /${artifactId}/lib
            false
        
    
    
        
            ${project.basedir}\src\main\bin
            /${artifactId}
            unix
            744
            
                *.sh
            
        
        
            ${project.basedir}\src\main\resources
            /${artifactId}/config
            unix
            644
            
                *.properties
                *.xml
                *.cfg
            
        
        
            ${project.basedir}\src\main\resources\config
            /${artifactId}/config
            unix
            644
            
                *.properties
                *.xml
                *.cfg
            
        
        
            ${project.basedir}\src\main\lib
            /${artifactId}/lib
            unix
            
                *.jar
            
        
    

4. 执行脚本run.sh

#! /bin/sh
cd `dirname $0`
PWD=`pwd`

for i in lib/*.jar;
do CLASSPATH="$CLASSPATH":$PWD/$i;
done

echo "CLASSPATH="$CLASSPATH

nohup java -server -Xmx1024m -Xms1024m -Xmn512m -classpath .:config:$CLASSPATH com.xxx.xxx.MyServer >/dev/null 2>&1 &

5. 打包后结果格式

artifactId-version-bin.tar.gz,解压后

artifactId

        ---config

            ---xxx.cfg

            ---xxx.properties

            ---xxx.xml

        ---lib

            ---xxx.jar

        ---run.sh

转载于:https://my.oschina.net/chengxiaoyuan/blog/682115

你可能感兴趣的:(用assembly把maven工程打成tar包)