头图

One of the biggest advantages of packaging your application as a jar and using an embedded HTTP server is that you can run these Web-enabled applications like any other application. Debugging Spring Boot applications is also easy; no special IDE plugins or extensions are required.

spring-boot:run is the java -jar command on steroïd, run as part of a Maven build, ensuring that all required parameters are passed to the application (eg resources). spring-boot:run will also ensure that the project is compiled by executing the test-compile lifecycle goal before running the application.

When running java -jar, a new JVM instance is started with all the arguments passed to that JVM. For example, using the Spring documentation example:

java -Xdebug -Xrunjdwp:server=y, \
 transport=dt_socket, address=8000, suspend=
-jar target/myproject-0.0.1-SNAPSHOT.jar

A brand new JVM will be started with the given arguments. Make sure to include everything you need on the command line, such as classpath elements, application arguments, JVM options, etc.

When mvn spring-boot:run is run, a Maven build is started which will:

  1. Runs the test-compile lifecycle goal, which defaults to the resources:resources, compiler:compile, resources:testResources, compiler:testCompile goals of the Maven Resources and Compiler plugin.
  2. Starts the application with a series of parameters that depend on the Spring Boot Maven plugin configuration (pom.xml, parent and settings, command line, etc.) defined in the project.

These include:

  • Lots of classpath elements: target/class folders, which may contain resources and libraries needed by the application, Maven dependencies, etc.
  • Whether to fork the JVM (whether to create an entirely new JVM to run the application or reuse a Maven-built JVM), see the plugin's fork and agent parameters.

If the following phenomenon is observed:

In /src/main/resources/META-INF/resources/WEB-INF/ there is a spring boot application with jsp pages. If you use mvn spring-boot:run these pages can be served, but if you use java -jar, these pages will not be found by the application.

To get similar results with the java -jar command, you must include your resources in the classpath, e.g. javar -jar myapp.jar -cp $CLASSPATH;/path/to/my/project/target/classes/


注销
1k 声望1.6k 粉丝

invalid