Before Spring boot, I usually typed into war packages and posted them to tomcat, but I recently used Spring boot to type into jar packages. I didn’t understand why I wanted to type into jar packages at first. Isn’t war packages very good?
Another point is that since you don’t know how to use jar packages, you feel that it’s unnecessary. After a period of adaptation, I feel that it is necessary to type a jar package, and it is also very convenient to publish it, so it saves the installation of tomcat and other middleware.
Let’s talk about how to type a jar package. It’s actually very simple. The main thing is to configure the pom.xml file. The key points are as follows:
Be sure to write a jar.
Add the following configuration in <bulid>:
<build><!-- The name of the jar package --><finalName>gateway</finalName><plugins><!-- The jar package that needs to be referenced--><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins><!-- <finalName>gateway</finalName> --></build><!-- Warehouse address--><repositories><repository><id>spring-milestone</id><url>http://repo.spring.io/libs-release</url></repository></repository></repositories>
After configuring these, using the tools, I use myeclipse and mvan update projects.
Use the tool myeclipse to type jar package.
Step 1: Use debug configurations to package
Step 2: Display the page of debug configuratons.
1Select the following items in Maven Bulid;
2 Enter package in Goals option
3 Click the Debug button.
Step 3: The console outputs the information at 1: BUILD SUCCESS
2 The gateway.jar is processed under the target folder of the project. The jar package is completed.
Step 4: Test whether the jar package is available
Use the command form to cut into the directory where the jar exists; execute java jar ***.jar
It is best to see the following letter to indicate that the jar has been started.
Use browser to test. The project is available for login.
Step 5: Close the thread that starts the jar package.
1. If it is a Windows system, just close the command form.
2. If it is a Linux system, use the ps command to find the corresponding thread and use the kill command to kill the thread.
Let’s talk about the easiest way to jar. Use the command to enter the project path and execute: mvn package will be packaged by yourself. After the package is completed, you can see the corresponding jar package in the project output directory target.
Packaging has started.
Packaging is complete.
Jar can fight, so if you want to fight the war bag, then.
It is recommended not to use war packages for spring boot projects, because this is the way to eliminate them. But if you want to hit, configure it in the pom.xml file:
The following information is configured in <bulid>, and you can use eclipse to export the war package:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><configuration><warSourceExcludes>src/main/resources/**</warSourceExcludes><warName>gateway</warName></configuration></plugin>
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.