zoukankan      html  css  js  c++  java
  • eclipse 打包springboot成jar

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

    如下pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <artifactId>springboot-websocket</artifactId>
        <version>0.0.1</version>
        <name>springboot-websocket</name>
        <description>SpringBoot系列——WebSocket</description>
    
      
      <!--  继承spring-boot-starter-parent  -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.0.RELEASE</version>
            <relativePath/>
        </parent>
    
        <!-- 在引入一下通用的依赖 -->
        <dependencies>
            <!-- spring-boot-starter -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <!-- springboot web(MVC)-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!-- springboot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!--lombok插件 -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
    
            <!--热部署工具dev-tools-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
                <scope>runtime</scope>
            </dependency>
     
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-websocket</artifactId>
            </dependency>
    
            <!-- thymeleaf模板 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
                <dependency>
        <groupId>org.java-websocket</groupId>
    <artifactId>Java-WebSocket</artifactId>
    <version>1.3.8</version>
    </dependency>
        </dependencies>
    
        
        <build>
            <finalName>springbootWebSocket</finalName>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
    
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <configuration>
                            <encoding>utf-8</encoding>
                            <useDefaultDelimiters>true</useDefaultDelimiters>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
    
        </build>
    </project>

    主要注意下:

    <pluginManagement>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <configuration>
                            <encoding>utf-8</encoding>
                            <useDefaultDelimiters>true</useDefaultDelimiters>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
    步骤:
    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() {
        }
    
    }


  • 相关阅读:
    [BZOJ3295][Cqoi2011]动态逆序对 CDQ分治&树套树
    [BZOJ3230] 相似字串 后缀数组+RMQ
    [BZOJ4556][Tjoi2016&Heoi2016]字符串 后缀数组+主席树
    [BZOJ4044]Virus synthesis 回文自动机的DP
    [BZOJ2055]80人环游世界 有上下界最小费用最大流
    [BZOJ2502]清理雪道 有上下界网络流(最小流)
    [BZOJ2095][Poi2010]Bridges 最大流(混合图欧拉回路)
    [BZOJ2288&BZOJ1150]一类堆+链表+贪心问题
    [BZOJ4820]硬币游戏 KMP+高斯消元
    [BZOJ1559]密码 AC自动机+状压
  • 原文地址:https://www.cnblogs.com/fuanyu/p/14754613.html
Copyright © 2011-2022 走看看