Maven插件打包Java项目

  1. 将依赖JAR包输出到lib目录方式

打包命令:

mvn clean install -Dmaven.test.skip=true

运行方式:

java -Djava.ext.dirs=lib -cp java-study-1.0.jar java8.RunnableTest

运行结果:

hello, I am is testThread1.
hello, I am is lamda testThread2

 pom.xml配置:


        java-study-1.0
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    ${java.version}
                    ${java.version}
                    utf-8
                
            
            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                        copy
                        install
                        
                            copy-dependencies
                        
                        
                            
                            ${project.build.directory}/lib
                        
                    
                
            
        
    
  1.  打包成可直接运行的jar包,依赖包放入lib目录

打包命令:

maven clean install -Dmaven.test.skip=true

运行方式:

java -jar java-study-1.0.jar

 运行结果:

hello, I am is testThread1.
hello, I am is lamda testThread2

  pom.xml配置:


        java-study-1.0
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.7.0
                
                    ${java.version}
                    ${java.version}
                    utf-8
                
            
            
            
                org.apache.maven.plugins
                maven-jar-plugin
                3.0.2
                
                    
                        
                            true
                            
                            lib
                            java8.RunnableTest
                        
                    
                
            
             
            
                org.apache.maven.plugins
                maven-dependency-plugin
                3.1.1
                
                    
                        copy
                        install
                        
                            copy-dependencies
                        
                        
                            
                            ${project.build.directory}/lib
                        
                    
                
            
        
    

参考资料:

https://blog.csdn.net/puhaiyang/article/details/78380550

你可能感兴趣的:(打包构建)