Execute command in a separate cmd or terminal - java

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.

Related

Desktop entry runs but terminal closes immediately and launcher never runs

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 &

How to open/run java / .jar minimized by using cmd console?

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

Does command-line stop programs launched in command window when command window is closed?

When launching and executable jar from the command window, is the jar attached to that window? So when I close the command line the program stops running, or will it continue in the background?
If so, System.out.println() should that print to the command window open if I'd closed the first command window?
This is in Windows (server 2012)
java.exe is attached to the current running command shell or the batch script that launched it. javaw.exe will start it as a separate windows program without that attachment. Using javaw is approximately the same as running java -jar xyz.jar & on Linux.

open 2 jar files on linux command

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/

Start a java program without the console

I am trying to use this GUI mod for a Minecraft Server. I wrote a batch file so the server can start with more RAM. When I run just the .jar file, no command window opens and it runs just fine (of course with about 256mb ram) I was reading online that javaw starts a jar file without a command-line-console. But when I use javaw, the command console opens, but when I close it the program remains open. this is my batch file:
#echo off
"%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe" -jar -Xms1024m -Xmx1024m crafty.jar
#echo on
I don't understand java as well as most, so please try to be as clear as possible. Thanks
If you want to start a java program without console popup under windows, this should be helpful:
In command prompt type the following:
start javaw -jar -Xms1024m -Xmx1024m crafty.jar
If you want you can also write this as a batch file.
You should Create Shortcut of "%ProgramFiles(x86)%\Java\jre6\bin\javaw.exe", let's name it as Minecraft, then
edit the Properties of Minecraft shortcut. In the Target textbox, append -jar -Xms1024m -Xmx1024m crafty.jar in the end of javaw.exe
change the Start in as the folder which contains the crafty.jar
Double-click the Minecraft icon to star the server.
That's all.
Create a .bat file with
start javaw -jar yourjar.jar arg0 arg1
start javaw -jar yourjar.jar arg0 arg1
will open the console, but close immediately. it is different from running window .exe.
You will always get the command window opening and closing because you are starting it inside a command window or batch script (which launches an implicit command window to run itself).
In order not to get a command window you must open the file from "not a command window" i.e. an executable launcher.
Take a look at Launch4j which can run a java program from an exe. It can also hide-away the jar file inside the exe if you like.
http://launch4j.sourceforge.net/
There's a little YouTube clip showing them creating an exe from a jar.
A batch file is a way of starting the command prompt with the code pre-written, using javaw is a way of open then closing the prompt. Like I said a batch is a commands prompt you can't stop it from opening.
It's few years, but for windows today as for linux you have the supervisor (pytho based)
supervisor windows based on python

Categories