Maven 打包war文件

pom.xml設置

1.設置打包類型爲warjava

<packaging>war</packaging>

2.若是須要經過命令行的方式啓動,須要增長以下設置web

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring.boot.version}</version>
    <executions>
         <execution>
             <goals>
                 <goal>repackage</goal>
             </goals>
         </execution>
    </executions>
</plugin>

說明:這樣在war包中/META-INF/MANIFEST.MF中增長信息spring

Start-Class: com.xxx.Application
Spring-Boot-Classes: WEB-INF/classes/
Spring-Boot-Lib: WEB-INF/lib/
Spring-Boot-Version: 2.0.2.RELEASE
Created-By: Apache Maven 3.5.3
Build-Jdk: 1.8.0_172
Main-Class: org.springframework.boot.loader.WarLauncher

其中:apache

Start-Class爲標註爲@SpringBootApplication的類maven

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

其餘信息不用管,是spring boot loader讀取的,Main-Class爲WarLauncher表示啓動war,還有JarLauncher表示啓動jar。ide

3.若是工程中沒有web.xml文件,那麼須要增長設置,避免maven打包報錯spring-boot

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.1</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

4.設置spring bootui

有兩種方式來引入spring bootthis

a)在parent節點指定spa

b)在dependencyManagement節點引入,同時設置<type>pom</type><scope>import</scope>

相關文章
相關標籤/搜索