I know it may sound silly question but I am unable to understand the difference between mvn spring-boot:run
and java -jar
(.jar file generated with mvn install)
I have a spring boot application with jsp pages in /src/main/resources/META-INF/resources/WEB-INF/
. If I use mvn spring-boot:run
these pages are served. But If I use java -jar
these pages are not found by application.
The application that I am working on is at https://github.com/ArslanAnjum/angularSpringApi
UPDATE: It works with spring boot 1.4.2.RELEASE while I intend to use the latest version i.e., 1.5.8.RELEASE.
UPDATE: Well I solved the problem by putting jsps in src/main/webapp/WEB-INF/views/ and changing packaging type to war and then running this war using java -jar target/myapp.war and its working fine now.
When you run mvn spring-boot:run , you launch a Maven build that will: Run the test-compile lifecycle goals, by default it will be resources:resources , compiler:compile , resources:testResources , compiler:testCompile goals of the Maven Resources and Compiler plugin.
You can run a Spring Boot application from your IDE as a simple Java application, however, first you will need to import your project. Import steps will vary depending on your IDE and build system.
Short answer: spring-boot:run
is a java -jar
command on steroïd running as part of your Maven build, ensuring all required parameters are passed to your app (such as resources). spring-boot:run
will also ensure that your project is compiled by executing test-compile
lifecycle goals prior to running your app.
Long answer:
When you run java -jar
, you launch a new JVM instance with all the parameters you passed to this JVM. For example, using the Spring doc example
java -Xdebug -Xrunjdwp:server=y, \ transport=dt_socket, address=8000, suspend= -jar target/myproject-0.0.1-SNAPSHOT.jar
You will launch a brand new JVM with the given parameters. You need to make sure to include everything needed, such as classpath elements, application parameters, JVM options, etc. on the command line.
When you run mvn spring-boot:run
, you launch a Maven build that will:
test-compile
lifecycle goals, by default it will be resources:resources
, compiler:compile
, resources:testResources
, compiler:testCompile
goals of the Maven Resources and Compiler plugin. target/classes
folder which may contain resources and libraries required by your app, your Maven dependencies, etc. fork
and agent
parameter of the pluginAs per:
I have a spring boot application with jsp pages in /src/main/resources/META-INF/resources/WEB-INF/. If I use mvn spring-boot:run these pages are served. But If I use java -jar these pages are not found by application.
It's because the mvn spring:boot
command will make sure your target/classes
folder is present in the Classpath when your app is running. After compilation, this folder will contain target/classes/META-INF/resources/WEB-INF
among other things. Your app will then be able to find META-INF/resources/WEB-INF
and load them when asked. When you ran java -jar
command, this folder was probably not on the classpath, your app was then not able to find your resources. (these resources were copied from the src/main/resources
folder during the resources:resources
goal)
To have a similar result with your java -jar
command, you must include your resources on the classpath such as javar -jar myapp.jar -cp $CLASSPATH;/path/to/my/project/target/classes/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With