Home  >  Article  >  Java  >  How to deploy jar package in springboot

How to deploy jar package in springboot

王林
王林forward
2023-05-11 13:13:061628browse

Since springboot commonly deploys war packages, when it is changed to cloud development mode with multiple ports, the deployment is not used to it

After all, the war package must be placed in the root directory of tomcat whether it is accessed by the project name or not

This directory is restricted to only one project, and the login port is limited to the tomcat interface

Therefore, jar package deployment has become an inevitable method

1. Add pom settings

Static files need to be accessed, so the files under the static file webapp need to be re-specified. The specific configuration is as follows

<resource>
 <directory>src/main/webapp</directory>
 <targetPath>META-INF/resources</targetPath>
 <includes>
 <include>**/*.*</include>
 </includes>
 <filtering>false</filtering>
</resource>

2. The packaging method is from war Change the package to a jar package

1. Comment the war package mode

<!--<packaging>war</packaging>-->
<packaging>jar</packaging>

2. Comment the war-plugin

<!--<build>
 <plugins>
 <plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.0.0</version>
		</plugin>
	</plugins>
</build>-->

<build>
<plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 <configuration>
 <mainClass>org.supwisdom.Application</mainClass> 
 </configuration>
 </plugin>
</plugins>
</build>

3. Comment out spring-boot-starter-tomcat related dependencies

4. Comment out SpringApplicationBuilder configure## in Application.java
#

// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// return application.sources(Application.class);
// }
 
 public static void main(String[] args) throws Exception {
 	System.setProperty("spring.devtools.restart.enabled", "false");
 SpringApplication.run(Application.class, args);
 }

Startup method:

cd The current service pom.xml is in the same directory


mvn clean package
java -jar target/***.jar
But the actual Certain problems occurred during use. For example, during development, modifications to the static file code did not always respond, and clearing the browser cache was of no use.

Therefore, the cache exists in the jar packaged by springboot. , so it is better to comment out the above content during development

The above is the detailed content of How to deploy jar package in springboot. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete