MyEclipse springboot项目打包的流程

时间:2024-03-27 14:29:11

1、生成jar包

(1)打开命令行窗口

         命令:cmd

(2)进入项目的根目录(与pom.xml同一级)

          命令:cd  D:\myeclipse2017\myeclipse2017namespace\springboot

(3)执行命令

          命令:mvn clean package

          注释:生成的jar包在target目录下,名称为“项目名称-版本号.jar”

          示例:MyEclipse2017 springboot项目打包的流程

(4)启动jar包

         命令:java -jar target/jar包名称

         示例:java -jar target/springboot-0.0.1-SNAPSHOT.jar

 (5)此时项目已经启动成功,可以进行访问了

          示例:http://localhost:8081/selectById?id=1

2、生成war包

(1)在pom.xml中配置<packaging>war</packaging>

(2)添加依赖

        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
          <scope>provided</scope>
      </dependency>

(3)在插件中配置项目名称

          <build>
              <finalName>springboot</finalName>
             <plugins>
                 <plugin>
                     <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>
                </plugin>
        </plugins>
  </build>

(4)创建ServletInitializer.java,继承SpringBootServletInitializer ,覆盖configure(),把启动类Application注册进去。外部web应用服务器构建Web Application Context的时候,会把启动类添加进去。

public class ServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

(5)右键---->Run As------>Maven install

(6)生成的war包在target中,将war包放在tomcat的webApp下,启动tomcat,

(7)访问项目时要添加项目名称

       示例:http://localhost:8081/springboot/selectById?id=1