A spring boot project, if packaged into a jar file, can be separated from the IDE and started directly through the Java-jar command, which is convenient. Maven Project
The first way:
IntelliJ idea under Start
First modify the packaging of the Pom as a jar
Open the Terminal window CD into this item 1. Perform MVN clean package
Springbootweb01-0.0.1-snapshot.jar file 2 can be generated under the target directory . Get Dependency Pack
Perform MVN clean package dependency:copy-dependencies
The dependency folder can be generated in the target directory, which is the project's dependency pack 3. New Mylib folder under Target
Copy both the hit package and the dependency pack to the Mylib folder
Execute the following statement deployment
Java-djava.ext.dirs=mylib-jar Mylib/springbootweb01-0.0.1-snapshot.jar
Because the target file is often changed due to project execution, such as the MVN clean operation, you can copy the Mylib folder to an external folder, such as on the Mylib folder on the desktop
CMD into CD d:\Users\Desktop
Perform
Java-djava.ext.dirs=mylib-jar Mylib/springbootweb01-0.0.1-snapshot.jar
You can start the project from the IDE.
You can also write a start.cmd file,
Create a new Bin folder under the Mylib folder, build a Start.cmd,
Java-djava.ext.dirs=mylib-jard:/users/desktop/mylib/springbootweb01-0.0.1-snapshot.jar
Note that the path uses "/" instead of "\" in Windows
Use-djava.ext.dirs to use ext Class Loader
Using-CP, which uses app Class Loader, should actually use app ClassLoader, so it's just a tricky way to do it. The second way:
An auto-generate script plug-in using Maven
Appassembler-maven-plugin
Configuration reference: Generating startup scripts using the Appassembler-maven-plugin plug-in
To generate a startup script using the Appassembler-maven-plugin plug-in
Executed under the Intellijidea terminal
MVN cleanpackage appassembler:assemble
If you report org.springframework.core.env.EnvironmentCapable error, then check the pom dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactid>spring-core </artifactId>
</dependency>
is the scope of test
Another note is: to
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-maven-plugin</artifactid>
</plugin>
Comment out, reason for reference: https://my.oschina.net/tridays/blog/858378
When using Appassembler-maven-plugin, do not use this plugin.
When you get to Target\springbootweb01\binspringbootweb01.bat, you can start.
There are two ways to terminate: Ctrl + C in intellijterminal
or NETSTAT–NAO|FINDSTR 8080 pid, forced to kill
If you want to change the port, modify it directly in the target\springbootweb01\conf\application.properties, then restart it, no need to repackage.
If you want to deploy to a production environment, just deploy the TARGET\SPRINGBOOTWEB01 folder to the server.
Relatively, the first way is to do it yourself, and the second way is more perfect.
Gradle
Under Gradle, add dependencies First, and specify a good springbootversion version
dependencies {
classpath ("Org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}")
}
After using the Gradle build under Terminal, you create folders such as Libs folder and resources under the Builds folder, and then the direct CD goes to Libs to execute Java–jarcore-0.0.1-snapshot.jar
These are the packaging and publishing methods for the Spring boot project built by MAVEN and Gradle under Windows
Execute the JAR pack transfer To/root directory directly under the Linux virtual machine Java-jar Xxx.jar can be started on the virtual machine