0

我正在编写一个在 Red Hat Enterprise Linux 5 服务器上运行的 Java Swing 应用程序,我想启动 jEdit 来查看日志文件。

这是一些示例代码。

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

}

输出是:

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

如果我将 cmd 输出复制并粘贴到终端窗口中,它运行良好。

我尝试了一堆 cmd 值,但我永远无法让 jEdit 窗口可见。

通过更改,此过程在 Windows 上运行良好。

我在 Linux 上做的事情可能吗?

提前致谢!

4

5 回答 5

2

由于 jEdit 是用 Java 实现的,也许更容易检查main方法的源代码(在 jedit.jar 中包含的清单文件中声明的类中)所做的事情,并且根本不使用就做同样的事情Runtime.getRuntime().exec()

如果您确实想坚持使用它,您可以尝试将单个命令作为数组传递给 exec(),这通常为我解决了此类问题。

于 2009-11-12T20:29:44.193 回答
1

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

于 2009-11-12T20:36:44.957 回答
1

Runtime.exec()需要特别注意。接受 a 的 exec 方法String使用空格字符作为分隔符将字符串分解为命令。您需要使用接受String[]. 在这里阅读更多,特别是在底部附近。

于 2009-11-13T01:24:00.843 回答
0

/usr/bin/jedit我猜Jedit 有一个启动器脚本。只需jedit在命令提示符下键入即可运行它,至少在当前版本 4.5 中是这样。尝试该脚本而不是显式java命令。

于 2012-09-18T06:45:17.093 回答
0

我做过一次,我遇到了同样的问题

我所做的是将命令行写入文本文件,然后将文本文件作为 shell 脚本文件执行。它对我来说很好。

于 2010-01-21T17:43:05.413 回答