本篇文章帶給大家的內容是關於springboot中war包和jar包的詳細介紹(程式碼範例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。
本篇和大家分享的是透過maven對springboot中打war包和jar包;war通常來說生成後直接放到tomcat的webapps下面就行,tomcat配置自動解壓war,而jar一般通過命令列部署與啟動;
首先,來實戰怎麼產生war包,主要來說可以分為3個步驟:
@SpringBootApplication public class WebApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(WebApplication.class); } // public static void main(String[] args){ // // } }
<!--war包-排除内置tomcat--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--war包-执行程序入口 --> <configuration> <mainClass>com.platform.WebApplication</mainClass> </configuration> </plugin>
1 <packaging>war</packaging>
public static void main(String[] args) throws ParseException, Exception { SpringApplication springApplication = new SpringApplication(WebApplication.class); springApplication.setBannerMode(Banner.Mode.OFF); springApplication.run(args); }
<!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-tomcat</artifactId>--> <!--<scope>provided</scope>--> <!--</dependency>-->
<!--打jar包--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <!--<addClasspath>true</addClasspath>--> <!--<classpathPrefix>lib/</classpathPrefix>--> <!--main入口--> <mainClass>com.platform.WebApplication</mainClass> </manifest> </archive> <!--包含的配置文件--> <!--<includes>--> <!--<include>*.yml</include>--> <!--<include>*.properties</include>--> <!--<include>templates/**</include>--> <!--<include>static/**</include>--> <!--<include>*.xml</include>--> <!--</includes>--> </configuration> </plugin>
1 <packaging>jar</packaging>
以上是springboot中war包和jar包的詳細介紹(程式碼範例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!