Spring Boot runnable Jar file for production?
You can use the .jar
for production too. Jars are easy to create. Spring boot jar can simply be managed automatically by the production server, i.e. restart the jar and etc.
It also has embedded Tomcat and the Tomcat configuration can be modified and optimized using the .properties
file or inside Java if you need that.
Generally, there are almost no reason to use .war
over .jar
, but it is up to you what you prefer.
Deploying Webflux application Jar file
There are two ways you could deploy a spring-boot application.
- Running as a standalone JAR file
- Deploy as a WAR file into a tomcat (For Spring WebFlux application this is not supported).
Deploy as a standalone JAR
To generate an executable JAR we could either use spring-boot maven plugin or spring-boot gradle plugin depending on your use case.
Spring Boot Maven Plugin
- Add following to the
pom.xml
.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- Run following command to generate the executable.
mvn clean package spring-boot:repackage
- Then run the generated JAR file with following command.
java -jar <path-to-generated-jar>/<app-name>.jar
Spring Boot Gradle Plugin
- Run following command to generate the executable.
./gradlew bootJar
- Then run the generated JAR file with following command.
java -jar <path-to-generated-jar>/<app-name>.jar
Spring boot running a fully executable JAR and specify -D properties
There are two ways to configure properties like that:
1:
By specifying them in a separate configuration file. Spring Boot will look for a file named like JARfilename.conf
which should be stored in the same folder like the JAR file. There you can add the environment variable JAVA_OPTS
:
JAVA_OPTS="-Dpropertykey=propvalue"
2:
Or you can just specify the value for the environment variable in the shell before you execute the application:
JAVA_OPTS="-Dpropertykey=propvalue" ./myapp.jar
Have a look at the documentation for the complete list of available variables: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#deployment-service
Regarding your second question: To execute a JAR, you don't need a JDK, a JRE is sufficient (but you need at least that, if you don't have any java installed on the server, the application won't run).
Related Topics
How to Compare Two Double Values in Java
How to Avoid Installing "Unlimited Strength" Jce Policy Files When Deploying an Application
Android Studio Google Jar File Causing Gc Overhead Limit Exceeded Error
How to Add Parameters to a Http Get Request in Android
Noclassdeffounderror: Android.Support.V7.Internal.View.Menu.Menubuilder
How to Get the Ip of the Computer on Linux Through Java
Environmental Variables Not Seen in a Cron
Problems Installing Java Ee Sdk on Linux
Decibel Values at Specific Points in Wav File
Why Do I Get "Exception; Must Be Caught or Declared to Be Thrown" When I Try to Compile My Java Code
Java: How to Get a Class Literal from a Generic Type
Why Does Arrayindexoutofboundsexception Occur and How to Avoid It in Android
Get Battery Level and State in Android
Service Discovery Failed Exception Using Bluetooth on Android
How Set Background Drawable Programmatically in Android