Launching jEdit From Java Swing App Using Runtime.getRuntime().exec()

1k views Asked by At

I'm writing a Java Swing Application running on Red Hat Enterprise Linux 5 server that I would like to launch jEdit to view log files.

Here is some example code.

public static void main(String[] args) throws IOException, InterruptedException {

    String cmd = "sh -c \"java -jar /tmp/jEdit/jedit.jar /tmp/test.txt\"";

    System.out.println(cmd);

    Runtime.getRuntime().exec(cmd);

}

The output is:

sh -c "java -jar /tmp/jEdit/jedit.jar /tmp/test.txt"

If I copy and paste the cmd output in a terminal window, it runs fine.

I have tried a bunch of cmd values, but I can never get the jEdit window to be visible.

With changes, this process works fine on Windows.

Is what I'm doing possible on Linux?

Thanks in advance!

5

There are 5 answers

0
Fabian Steeg On

As jEdit is implemented in Java, perhaps it would be easier to check the source for what the main method (in the class declared in the manifest file included in the jedit.jar) does and do the same thing without using Runtime.getRuntime().exec() at all.

If you do want to stick with it, you could try passing the individual commands as an array to exec(), this often solved such problems for me.

1
Benjamin Cox On

Linux uses the concept of display ports for its X-Windows system. This allows it to maintain a different desktop environment for each user. It also allows a user on remote machine to run a desktop app from the first machine but see the UI on the remote.

Windows, having only one available desktop environment at a time, does not.

First thing you definitely have to do is add the environment variable "DISPLAY=localhost:0" to the environment from which you are launching this. However, you may also need to run 'xhost +localhost' or this may not be allowed.

Double-check, too, that you didn't successfully launch a bunch of jEdit processes that are now zombies (using top) and kill them if necessary (using kill).

2
Nemi On

Runtime.exec() needs some special attention. The exec method that accepts a String uses the space character as a delimiter to break up the string into commands. You need to use the exec method that accepts a String[]. Read more here, specifically near the bottom.

0
Jarekczek On

Jedit has a launcher script, /usr/bin/jedit I guess. Simply typing jedit in command prompt runs it, at least in current version, 4.5. Try that script instead of explicit java command.

0
marionmaiden On

I´ve done this once and I got the same problem

What I've done is to write the command line into a text file and then execute the text file as a shell script file. It worked fine for me.