WhiteTiger
WhiteTiger

Reputation: 776

How to make a java executable run in the background instead of the foreground?

I wrote a shell script to run a set of experiments so I won't have to do it manually. The script runs a java .jar file 30 times, and runs a set of those 30 times 17 times changing a few variables in between.

I invoke the program like this:

java -Djava.library.path=/Users/me/Desktop/Cfiles/DynamicCTGLayout/build/Release  -jar [name of .jar file]

However, I can't do anything in parallel while the program runs because when this line is executed, the java executable pops out at the forefront of the screen. In essence when I work on something else it gets interrupted every 1-1.5 minutes. so I'm looking at a few hours I can't actually use the computer.

Is there a way to invoke an executable so that it doesn't pop out on top of all the other programs?

Sincerely, WhiteTiger

Edit: Basically I'm looking for the Mac OSX equivalent to Windows'

start /min java [arguments]

Upvotes: 5

Views: 9636

Answers (5)

pillravi
pillravi

Reputation: 4143

I had the same problem when executing a program encapsulated in a JAR. I fixed it by adding the option -Djava.awt.headless=true to my command line invocation (see oracle docs and this question). So, you would run:

java -Djava.awt.headless=true -Djava.library.path=/Users/me/Desktop/Cfiles/DynamicCTGLayout/build/Release -jar [name of .jar file]

Upvotes: 3

Marcelo
Marcelo

Reputation: 11308

In Windows you can use:

start /min java [parameters]

This will start the program minimized and not take focus away. I tested it successfully in Windows 7 Professional x64.

Upvotes: 0

Martin Thurau
Martin Thurau

Reputation: 7644

If you use Linux (or an OS that uses X) cou could put a "fake" X server in place using Xvfb and set the DISPLAY variable for the JAVA app so that it uses this disaply. The downside: You can't access the GUI of the launched application (which is, to my understanding, not a problem in your case).

On one shell: Xvfb :2

On aother shell: DISPLAY=:2 java -jar ...

Upvotes: 0

kuriouscoder
kuriouscoder

Reputation: 5582

You can do this in unix by adding & symbol at the end of the command line, it pushes a process to background

Upvotes: 2

Femi
Femi

Reputation: 64700

Use javaw instead of java (you might need to make sure its on the path). This will run it without any console.

javaw -Djava.library.path=/Users/me/Desktop/Cfiles/DynamicCTGLayout/build/Release -jar [name of .jar file]

Upvotes: 6

Related Questions