tags:

views:

197

answers:

3

Is it possible to specify which X display the JVM is to launch it's windows on through the JVM? I am thinking something like this

java -DISPLAY=THE_DISPLAY_I_WANT:0.1 -jar my.jar

I looked at the man pages and I can't find anything.

or do I need to wrap my call to the jvm in a shell script like this

#/bin/sh
export DISPLAY=THE_DISPLAY_I_WANT:0.1
java -jar my.jar

I don't want to make a script just to specify an argument that can be past directly to the JVM.

PS: No, I don't want to change my enviroment DISPLAY variable I want to launch the JVM on whichever DISPLAY I like :)

Update Responding to the question "Why does it matter if I use the second solution" Using the second solution, If I would like to start a jvm session on several different displays I would have to set the DISPLAY for each session.

What I am looking for is like what you can do with Xprograms

try xterm -display my_display:0.0 So my question is can I do this with the jvm, I can't see it documented anywhere. If it can't be done then the correct answer should be "No you can't", I already know the alternative :)

Thanks

A: 

If you are using sh, bash or the like you can just do

DISPLAY=THE_DISPLAY_I_WANT:0.1 java -jar my.jar
Peter Lawrey
I know I can do that, but that's not my question
hhafez
see my update to the question
hhafez
A: 

If you'd be content with your suggestion,

java -DISPLAY=THE_DISPLAY_I_WANT:0.1 -jar my.jar

then I'm not sure why you resist either of these:

DISPLAY=THE_DISPLAY_I_WANT:0.1 java -jar my.jar
env DISPLAY=THE_DISPLAY_I_WANT:0.1 java -jar my.jar

They don't modify the environment variable globally, if that's what you're concerned about. They only modify it for the new process (and whatever else it spawns). Other new processes will not be affected, and processes that were already running certainly won't be affected.

If that's not the issue, then I guess what you mean is that in the first example, you wouldn't really be modifying the DISPLAY environment variable, not even for the new Java process. You'd instead be counting on the X11 layer of the current JVM to have some other way of determining where to send its graphical output. I suppose it could work that way. Maybe every other Java program on Earth just ignores that other way and lets the JVM fall back to using the environment variable instead, as it works for non-Java programs.

But why does it matter? It's not as though your program is going to use the (unmodified) DISPLAY environment variable for something else, is it? Since it's not being used for anything else, you may as well just use it for its intended purpose, no?

Rob Kennedy
see my update to the question
hhafez
+3  A: 

Given your constraints on the answer, the answer you're looking for is "It can't be done"

I'm still curious why the second solution doesn't work for you. I realize it's not what you want to do, I just want to know why

basszero
I'm quite curious about that myself.
Joachim Sauer
The reason is because I'm developing for a multiscreen configuration, each screen is configured with a sperate display 0.0 0.1 0.n and so on. I don't want to have to do export DISPLAY=blah before I launch each JVM for each application. I wanted to know if I could just added it to the args :)
hhafez
as for the why it is clearly more convenient when you have many displays that you are dealing with and you don't want to change your default display.
hhafez
You don't have to re-export it, though. You just have to change the value temporarily for the current command, and that involves typing exactly as much as you would have typed anyway, if java supported a special option like xterm does.
Rob Kennedy