SpringBoot工程打包部署~

SpringBoot工程运行有三种方式:

  • 可执行Jar包(可脱离Tomcat,独立运行)
  • 可执行war包 (可脱离Tomcat,独立运行)
  • 标准war包 (需要部署到tomcat中运行)

打可执行Jar包

1、pom中添加构建依赖

<build>
	<plugins>
    	<plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
			
            
            <executions>
                <execution>
                    <goals>
                        
                        <goal>repackagegoal>
                    goals>
                execution>
            executions>
    
            
            <configuration>
                <mainClass>com.taotao.portal.PortalApplicationmainClass>
            configuration>
        plugin>
    plugins>
build>

2、执行打包命令

mavn clean package -Dmaven.test.skip=true

3、运行生成的jar包

java -jar xxx.jar

打标准War(需要放到外部Tomcat中部署运行)

1、修改启动类

// 继承SpringBootServletInitializer,重写配置方法。让SpringBoot启动类和Tomcat原生生命周期建立联系。这样我们启动Tomcat时,Tomcat才能正常启动SpringBoot应用
public class ManagerApplication extends SpringBootServletInitializer{
 
  //  将SpringBoot启动类和Tomcat建立联系
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
       return builder.sources(ManagerApplication.class);
   }
 
    public static void main(String[] args) throws InterruptedException {
        SpringApplication application = new SpringApplication(ManagerApplication.class);
        //application.setBannerMode(Banner.Mode.OFF);
         application.run(args);
    }
}

2、添加依赖

<dependencies>

    // ...
    
     <dependency>
         <groupId>org.springframework.bootgroupId>
         <artifactId>spring-boot-starter-tomcatartifactId>
         <scope>providedscope>
     dependency>
    
    // ...
    
dependencies>

<build>
	<plugins>
    	<plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
			
            
            <executions>
                <execution>
                    <goals>
                        
                        <goal>repackagegoal>
                    goals>
                execution>
            executions>
    		
            
            <configuration>
                <mainClass>com.taotao.portal.PortalApplicationmainClass>
            configuration>
        plugin>
        
        
        <plugin>
            <artifactId>maven-war-pluginartifactId>
             <version>3.0.0version>
        plugin>
    plugins>
build>

3、打包命令

mvn clean package -Dmaven.test.skip=true

4、运行

将打好的war包,拷贝到%TOMCAT_HOME%/webapps/, 然后正常启动tomcat即可

打可执行war包(仅限Web工程)

1、添加依赖

<build>
	<plugins>
    	<plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
			
            
            <executions>
                <execution>
                    <goals>
                        
                        <goal>repackagegoal>
                    goals>
                execution>
            executions>
    		
            
            <configuration>
                <mainClass>com.taotao.portal.PortalApplicationmainClass>
            configuration>
        plugin>
        
        
        <plugin>
            <artifactId>maven-war-pluginartifactId>
             <version>3.0.0version>
        plugin>
    plugins>
build>

2、 打包命令

mavn clean package -Dmaven.test.skip=true

3、运行方式

java -jar xxx.war

你可能感兴趣的:(SpringBoot工程打包部署~)