Trying to setup a desktop entry on ubuntu 21.04 for a .jar file. When I execute it manually with:
$ java -jar /home/usr/Documents/launcher.jar
It outputs some logs from the jar and seems to throw that process into the background.
So as long as the terminal is open it stays running.
But when I setup the .desktop file:
[Desktop Entry]
Type=Application
Terminal=true
Icon=/home/usr/Pictures/logos/launcher.png
Exec=java -jar "/home/usr/Documents/launcher.jar"
Name=Launcher
Comment=Launcher information here
And when I run it a terminal opens showing the logs as expected but then it just closes immediately after and the launcher never actually starts. I was able to take a screenshot of the terminal before it closed/exited and there was no errors or unexpected logging.
UPDATE 1:
I tried to see if running it manually with following command gave the same output and running it as a desktop app and it did. Failed to actually launch launcher.jar
$ gnome-terminal -e "java -jar /home/usr/Documents/launcher.jar"
Have you try to use nohup command?
Add it before your java command and redirect outputs:
nohup java -jar [...] > launcher.log 2>&1 &
Related
I found different possibilities to open Windows applications minimized from cmd.exe. Best related topics I found were:
open program minimized via command prompt and
Run Java console app as a daemon (background)
What I couln'd get working is running a .jar from cmd in a minimized or background state. The window still pops up in front with, e.g. :
START /min javaw -jar App.jar &
or
START javaw -jar App.jar --new-window/min
or other variations of these cmd options.
I made a workaround by setting it up in the application itself with
frame.setState(Frame.ICONIFIED)
But does anyone know how to do this by cmd, or what could be the problem (Win7 x64)?
I need to open run two jar applications in the same time
I know that to run a jar file you have to type
java -jar app1.jar
but I need to terminate the current process to run
java -jar app2.jar
How can I open app2 without closing app1 ?
Execute this bash command
( java -jar app1.jar ) &
( java -jar app2.jar )
The commands will execute in parallel subshells
You can run one, push it into the background, and then run the other.
Run the first command, press ctrl-z and then type bg.
This runs the command in the background, leaving your command line available for you to call you next command.
http://www.thegeekstuff.com/2010/05/unix-background-job/
The following process normally works for my startup scripts. However, when I introduce a command to execute a JAR file, it does not work. This script works while I am logged in. However, it does not work as a startup script.
In /etc/init.d I create a bash script (test.sh) with the following contents:
#!/bin/bash
pw=$(curl http://169.254.169.254/latest/meta-data/instance-id)
pwh=$(/usr/bin/java -jar PWH.jar $pw &)
echo $pwh > test.txt
Make script executable
In /etc/rc.local, I add the following line:
sh /etc/init.d/test.sh
Notes:
I make a reference to the script in /etc/rc.local, because this script needs to run last after all services have started.
Please do not ask me to change the process (i.e., create script in /etc/init.d/ and reference it from /etc/rc.local), because it works for my other startup scripts.
I have tried adding nohup in front of java command, and it still did not work.
Thanks
As written, there is insufficient information to say what is going wrong. There are too many possibilities to enumerate.
Try running those commands one at a time in an interactive shell. The java command is probably writing something to standard error, and that will give you some clues.
It is possible to execute external commands in java at run time.
However, what I am looking for is to actually open cmd or terminal and show that executing external command on screen.
I tried to execute a jar console application as java -jar jartool arguments, it works both on Windows and Ubuntu. The only problem is that, this does not open cmd or terminal separately. it runs the command in background.
We can use either ProcessBuilder and the start process or simply Runtime.getRuntime().exec.
I need to forcefully open the cmd or terminal. Java is configured to show console on windows but still no luck.
Any idea why this is happening or what should I do to force it to open cmd or terminal independent of current cmd or terminal.
I am invoking a java swing program from command program and after executing the java program the console remains open. My bat file contains :
set Gantt_Generator_v5.0="C:\Program Files\GANTT_GENERATOR_V5.0"
java -jar %Gantt_Generator_v5.0%\GANTT_GENERATOR_V5.0.jar "C:\Program Files\GANTT_GENERATOR_V5.0\test\Parameter_File.csv" FALSE
exit
When I close the command prompt the java application quits.
Tried options : changed the extension from .bat to .cmd but didn't work for me.
Any other solutions?
used "START JAVAW..." so the final Script is :
set Gantt_Generator_v5.0="C:\Program Files (x86)\GANTT_GENERATOR_V5.0"
start javaw -jar %Gantt_Generator_v5.0%\GANTT_GENERATOR_V5.0.jar "C:\Program Files (x86)\GANTT_GENERATOR_V5.0\test\Parameter_File.csv" FALSE