• springboot項目打jar/war包


    一、打jar包

      (1)不打入项目引用的第三方jar

      <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
               
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <useUniqueVersions>false</useUniqueVersions>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.badcat.Application</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>

      (2)打入项目引用的第三方jar

      <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <!--这里写上main方法所在类的路径-->
                    <configuration>
                        <mainClass>com.badcat.Application</mainClass>
                        <includeSystemScope>true</includeSystemScope><!--外部进行打包-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal><!---->
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    二、打war包

      (1)

    <packaging>war</packaging>

      (2)

        <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <!-- 打包war [2] 移除自带内置tomcat -->
                <exclusions>
                    <exclusion>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                        <groupId>org.springframework.boot</groupId>
                    </exclusion>
                </exclusions>
            </dependency>

      (3)

          <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>javax.servlet-api</artifactId>
                  <scope>provided</scope>
              </dependency>

      (4)

    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    
    // 打包war [4] 增加war的启动类
    public class WarStarterApplication extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
            // 指向Application这个springboot启动类
            return builder.sources(Application.class);
        }
    }
  • 相关阅读:
    连接多台机子的多个数据库webconfig
    md5
    JavaScript substring() 方法
    Coolite ComboBox 模糊查询
    2010暴强语录
    Response.ContentType 说明
    C#得到磁盘信息
    Coolite Toolkit 1.0版本在线demo
    关于IT人职业道德的反思(转)
    Coolite TextField添加回车事件
  • 原文地址:https://www.cnblogs.com/hmxs/p/13138679.html
Copyright © 2020-2023  润新知