eclipse 打包springboot成jar


因为springboot到生产环境是在部署到jar或者war,推荐用jar比较方便

如下pom.xml

<?xml version="1.0" encoding="UTF-8"?>

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0
    springboot-websocket
    0.0.1
    springboot-websocket
    SpringBoot系列——WebSocket

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

    
    
        
        
            org.springframework.boot
            spring-boot-starter
        

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

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

        
        
            org.projectlombok
            lombok
        

        
        
            org.springframework.boot
            spring-boot-devtools
            true
            runtime
        
 
        
            org.springframework.boot
            spring-boot-starter-websocket
        

        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
            
    org.java-websocket
Java-WebSocket
1.3.8

    

    
    
        springbootWebSocket
        
            
                src/main/java
                
                    **/*.xml
                
            
            
                src/main/resources
                true
            

        
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
        
            
                
                    maven-resources-plugin
                    
                        utf-8
                        true
                    
                
            
        

    

主要注意下:


            
                
                    maven-resources-plugin
                    
                        utf-8
                        true
                    
                
            
        
步骤:
1。选中项目,右击run as 顺序运行maven clean再maven install
2.打包成功之后,可以看到[INFO] BUILD SUCCESS ; 得到springbootWebSocket.jar包里有相关引用的jar
3.运行java -jar springbootWebSocket.jar
打包时注意:
1。不要在pom.xml引用关联外部的子模块或者父模块 2。因本项目使用websocket,在使用类SpringbootWebsocketApplicationTests测试时,
加上@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
package cn.huanzi.qch.springbootwebsocket;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SpringbootWebsocketApplicationTests {

    @Test
    public void contextLoads() {
    }

}