I'm familiar with the Spring Boot JSP sample application
However that example uses the WAR
packaging. Is it possible to do the same with <packaging>JAR</packaging>
?
My goal is to put JSP
s under src/main/resources/jsp
to simplify the structure of my app.
The Spring Boot Maven Pluginimplement a custom ClassLoader to locate and load all the external jar libraries now nested inside the package. automatically find the main() method and configure it in the manifest, so we don't have to specify the main class in our java -jar command.
Run the mvn package command and you have successfully converted your spring boot application from JAR into a WAR file. You can safely deploy these WAR files on application servers like Tomcat, GlassFish etc.
The spring-boot-loader modules lets Spring Boot support executable jar and war files. If you use the Maven plugin or the Gradle plugin, executable jars are automatically generated, and you generally do not need to know the details of how they work.
You cannot use a spring-boot-plugin-manipulated-jar as a "normal" dependency, as its structure has been changed to be "startable" as a standalone JAR for Spring.
As @Andy Wilkinson said, there are limitations related to JSP. Please package your application as war
and execute as jar
. This is documented at spring site.
With Tomcat it should work if you use war packaging, i.e. an executable war will work (...). An executable jar will not work because of a hard coded file pattern in Tomcat.
Deprecated, old answer
Yes, this is possible with Spring Boot.
Take look at this example: https://github.com/mariuszs/spring-boot-web-jsp-example.
For doing this use spring-boot-maven-plugin or gradle equivalent.
With this plugin jar is executable and can serve JSP files.
$ mvn package $ java -jar target/mymodule-0.0.1-SNAPSHOT.war
(Note the extension of the artifact in the above command .war) or just
$ mvn spring-boot:run
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