I tend to use the runnable JAR during development, but I need a WAR for deployment.
I've followed this article about converting from a JAR to WAR Spring Boot Gradle build.
However, right now, everytime I switch the builds from one to the other, I have to comment and uncomment the specific parts of the build file.
Is there a cleaner way of handling allowing for both a JAR and WAR build?
Spring boot war is defined as creating packaging of application as a war file. As we know that default packaging of the application is jar is deployed on tomcat server. We can also generate war file deployment of spring boot applications by using tomcat, JBoss, and weblogic server instances.
If you use the Spring Boot build tools, marking the embedded servlet container dependency as provided produces an executable war file with the provided dependencies packaged in a lib-provided directory.
JAR files allow us to package multiple files in order to use it as a library, plugin, or any kind of application. On the other hand, WAR files are used only for web applications. The structure of the archives is also different. We can create a JAR with any desired structure.
The war that gets build for deployment (that is if you added the spring-boot maven plugin) is just as runnable as a jar file.
java -jar mywar.war
And presto it starts with an embedded server, you can deploy the same war to your server and then it doesn't use an embedded server.
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