5

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]
pillravi
  • 4,035
  • 5
  • 19
  • 33
WhiteTiger
  • 758
  • 1
  • 7
  • 21
  • @Marcelo, I was almost going to point you to [this question on meta](http://meta.stackexchange.com/questions/88046/is-58-accept-rate-bad) before I noticed the smiley! You got me. ;) – Kelly S. French May 19 '11 at 21:55
  • 1
    Possible duplicate of [How can I prevent command line java processes from stealing focus in OSX?](http://stackoverflow.com/questions/8911748/how-can-i-prevent-command-line-java-processes-from-stealing-focus-in-osx) – pillravi Sep 01 '16 at 20:29

5 Answers5

6

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]

Femi
  • 64,273
  • 8
  • 118
  • 148
  • thnx Femi, but not quite what I'm looking for I mean I want the entire GUI of the program to pop in the background and the current program I'm working with to stay as "the currently selected program", if that makes sense – WhiteTiger May 19 '11 at 22:01
  • Oh: your question didn't say anything about the GUI, just the executable, which I (and others) assumed was the console. Bad question. In any case: are you using Swing? SWT? some other graphics toolkit? – Femi May 19 '11 at 22:05
  • @Femi `javaw` is not available on OSX – pillravi Aug 31 '16 at 14:41
3

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]
Community
  • 1
  • 1
pillravi
  • 4,035
  • 5
  • 19
  • 33
2

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

Kelly S. French
  • 12,198
  • 10
  • 63
  • 93
kuriouscoder
  • 5,394
  • 7
  • 26
  • 40
0

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

Martin Thurau
  • 7,564
  • 7
  • 43
  • 80
0

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.

Marcelo
  • 11,218
  • 1
  • 37
  • 51
  • Okay, this is more in the direction of what I'm looking for... What would be the command to do this on MacOSX? – WhiteTiger May 20 '11 at 05:48
  • Added untested solution for MacOSx – Marcelo May 20 '11 at 13:59
  • this also doesn't seem to work since I get an error saying open: invalid option -- D referring to the option -Djava.library.path=/Users/borisshabash/Desktop/School/CMPT/894/jViz/Cfiles/DynamicCTGLayout/build/Release even if I try without that option, the Terminal still loses focus and becomes deselected – WhiteTiger May 20 '11 at 18:52
  • I will remove that part from my answer and give up, because I really don't have an environment to test. – Marcelo May 20 '11 at 20:07