4

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!

3
  • 1
    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 Commented Mar 22, 2020 at 14:16
  • Yes it's a server side code API's which has to be running always Commented Mar 22, 2020 at 14:18
  • 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. Commented Mar 22, 2020 at 14:26

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 & 

1 Comment

This is the best way to deploy jar files. for example. nohup java -jar abc-api.jar >/dev/null 2>&1 & nohup java -jar cde-api.jar >/dev/null 2>&1 &
0

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.

1 Comment

No I do not want to use docker, I just wan to know is it industry practice to embed jar into war/ear and deploy in jboss
0

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).

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.