4
votes

I'm new to deployment, I've jar file as a package how should I go ahead for deployment in my prod server?

My prod server is basically an EC2 machine running on AWS

  1. Shall I just run java - jar "jar file"? is this the practiced way for prod servers?
  2. Shall I package .jar file to ear/war and deploy in tomcat/jboss server?

Help appreciated!

5
You haven't told us what your program does. If it's a server that's supposed to be always running, it's not deployed the same way as something that's supposed to run as a daily batch job, or as an interactive tool - Joni
Yes it's a server side code API's which has to be running always - A Lovely
Too little data to answer your question. You didn’t specify what infrastructure you have at your disposal. For example, you choose different options and have different constraints when you deploy to k8s, Elastic beanstalk, on prem server etc. - Lesiak

5 Answers

2
votes

Both of the approaches you described are valid.

For small web APIs that include their own application server (e.g. Spark, Javalin, Spring Boot) on Linux servers, I start a screen session and run java -jar. This allows me to exit the SSH session (disconnect from the server) without terminating the program.

For other Spring applications that don't include an application server, I package the code into a WAR and copy it to an application server's deployment directory. For Tomcat, that's webapps. The application server can then read the WAR and spin up a running instance (assuming hot-deploy is enabled).

Tomcat in particular also has a web page where you can upload your WAR file to deploy it.

0
votes

This is basically up to your preference and usual standard at your place. We have services in Docker that basically have exec java -jar param param... at the end of entry-point.sh script. You can run whole Tomcat, etc.

0
votes

If you're using Spring Boot (which is a good idea), then java -jar is perfectly fine - you can use embedded Tomcat and skip installing dedicated application server (or, to be precise, servlet container).

0
votes

Second approach is preferred over first in Jboss servers as things can be easily done through console. You can control the deployment of the application on the servers. If say you don't want to deploy the jar on all the servers part of cluster ,that can be taken care.

0
votes

If you would that the program is still held run after disconnecting from SSH or closing the terminal in Linux. You can use this command:

nohup java -jar file.jar &