使用maven 将springboot打包成jar 并执行

一、示例xml



    4.0.0

    com.wqb
    eureka_client
    0.0.1
    jar

    eureka_client
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.2.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        


        
            org.springframework.cloud
            spring-cloud-starter-eureka
        
        
            org.springframework.boot
            spring-boot-starter-web
        



    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Dalston.RC1
                pom
                import
            
        
    


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            


            
            
                org.apache.maven.plugins
                maven-jar-plugin
                2.6
                
                    
                        
                            true
                            lib/
                            com.wqb.eurekaclient.EurekaClientApplication
                        
                    
                
            


            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                2.10
                
                    
                        copy-dependencies
                        package
                        
                            copy-dependencies
                        
                        
                            ${project.build.directory}/lib
                        
                    
                
            


            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.17
                
                    true
                
            




        





    
   
    
        spring-milestones
        Spring Milestones
        https://repo.spring.io/milestone
        
            false
        
    





二、xml重点标签详解

主要注意三点:

1、设置jar入口类

2、把依赖的jar包打到生成的jar内部的lib目录下

3、打包时忽略junit测试

具体见xml内标签上注释


三、jar打包&执行

1、maven打包:mvn clean package

生成的jar包会在项目的target目录下

2、运行jar包,命令行下:

java -jar xxxx.jar




你可能感兴趣的:(maven,java开发经验整理)