I am trying to add my java jar application to Ubuntu as service so that when the Ubuntu server is restarted I dont need to manually run the jar command to run my application. At present I have to run this cmd on the terminal
java -jar myapp.jar -conf conf.json.
I came accross this link which would have solved my problem but for some reason the service is not running when i run the service as described in that website.
http://www.jcgonzalez.com/ubuntu-16-java-service-wrapper-example
Can someone please help me!!
I think your bash script should have "nohup" like this:
nohup java -jar myapp.jar -conf conf.json &
Related
I used to run a jar in background with below syntax on a linux machine as below :
java -jar ./target/myjar-0.0.1-SNAPSHOT.jar > /dev/null 2>&1
But now i have a requirement to run the same jar in background on the Powershell on a windows machine . (I am not using Powershell Core version which allows use of & keyword for running background jobs , my version is 5.1)
I tried running my jar in background as below based on this answer here on StackOverflow (https://stackoverflow.com/a/25035181/4193280):
Start-Job -ScriptBlock {
& java -jar ./target/myjar-0.0.1-SNAPSHOT.jar >console.out 2>console.err
}
But still the jar is not executing and i am not able to connect on my application on port 9090 (that is where i have configured it to run) .
Please let me know and help where i am missing the point so that i can execute the jar in background . Thank you .
my server program needs to be launched on the startup of an EC2 instance. At the minute im just launching it from my SSH with the following commands:
java -jar ~/DocumentManager/DocumentServer-0.2.jar
I tried adding this to the .bashrc and /etc/rc.local files but they only seem to work when i ssh in.
Anyone know how to make it so an instance of my application is launched when the computer boots?
Thanks,
Ben
It's possible you can create a script java_server_launch.sh like this:
#! /usr/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
JAVA=/usr/bin/java
MY_SERVER=/home/your_username/DocumentManager/DocumentServer-0.2.jar
USER=your_username
/bin/su - $USER -c "$JAVA -jar $MY_SERVER &"
Put your script under /etc/init.d directory, and then use the command:
update-rc.d java_server_launch.sh defaults
more on update-rc.d command by using man update-rc.d.
Hope this help.
Regards.
Add ampersand(symbol '&') at the end of the command.
For example, in your case, java -jar ~/DocumentManager/DocumentServer-0.2.jar &
Old question, but my answer might be helpful for people who look in future.
You can also run your program as a service which automatically run on ec2 container reboot. Below link worked for me:
https://medium.com/#lizlieholleza/run-your-java-application-as-a-service-in-an-ec2-instance-amazon-linux-d7c7b4c0b2f4
Hi all i want to run a java application as backend process.that is like tomcat server.For that i had developed one application.and made one class as main class and calling from one script file .i.e(startup.sh) file.in startup.sh file i was calling one class.that is MainMethodClass.In main method class i had written my business logic.when i am running this app in linux server from using putty is is working until putty window is not closed.As closed after putty window it is also stopped.but i need to run this app even i closed also.How can i achieve this.
Nohup will detach a process you run from your current console and let it continue when you close the terminal. Run something like this.
nohup java -jar my.jar &
By default it will pipe the output to nohup.out, so if you don't want that you could try:
nohup java -jar my.jar > /dev/null &
This problem is not related to java, its actually something related to the way linux operates.
You need to do following:
nohup <your_application_command> &
Note the "nohup" and "&" at start and end respectively.
You should be able to do something like:
nohup java -jar MyApplication.jar &
On a linux machine you can create a service for your jar( executable jar like spring boot )
# Set the Application as Service
ln -s $APP_BASE/bin/$APP_NAME.jar /etc/init.d/$APP_NAME
echo "Starting the application as service"
service $APP_NAME start
In Ubuntu 10.10, System/Preferences/Startup Applications, I am trying to add a .jar program. If the program sits in home/john/this-folder/app.jar, what would I put in the command line for it to run on start-up?
java -jar /home/john/this-folder/app.jar [optional arg if any]
java - the Java application launcher
Note that you need to include jar in classpath if you java app needs dependecies.
You do that by:
java -jar /yourApp.jar -cp /home/zzz/libs/
I am trying to use the NSSM - the Non-Sucking Service Manager to run Jetty that is included with Solr as a Windows Service. Everything works fine by placing Java.exe in my C:\solr folder and setting up NSSM by pointing to this Java.exe along with the following parameters -Dsolr.solr.home=C:/solr -jar start.jar
You can also run C:\solr\java.exe -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar from the command line without installing the service as a test which works fine.
If I leave Java.exe in the System32 folder though, things will not work and I get a java.lang.ClassNotFoundException for org.mortbay.xml.XmlConfiguration.
I can of course run C:\solr\java -Dsolr.solr.home=C:/solr -jar C:/solr/start.jar as well since Java is in my PATH.
If seems like I need an additional classpath option or something but I don't know?
I ended up using the following in the arguments for NSSM: -Dsolr.solr.home=C:/solr/ -Djetty.home=C:/solr/ -Djetty.logs=C:/solr/logs/ -cp C:/solr/lib/*.jar;C:/solr/start.jar -jar C:/solr/start.jar