Is there a way to shutdown Eclipse cleanly from the command line, such that files and workspaces are saved? kill -3 doesn't do anything. kill -1 and kill -15 (default) causes Eclipse to exit abruptly with JVM termination popup. kill -9 does the same thing.
有没有办法从命令行干净地关闭Eclipse,以便保存文件和工作区?杀-3没有做任何事情。 kill -1和kill -15(默认值)导致Eclipse突然弹出JVM终止弹出窗口。 kill -9做同样的事情。
The use case is that I'm working remotely on a machine with Eclipse loaded on it, and I want to save memory by closing Eclipse, but I want Eclipse to save its state first.
用例是我在装有Eclipse的机器上远程工作,我希望通过关闭Eclipse来节省内存,但我希望Eclipse先保存其状态。
I could use VNC or some alternative desktop sharing software, but that's really heavy-weight, and I'd much prefer a command line solution.
我可以使用VNC或一些替代的桌面共享软件,但这非常重,我更喜欢命令行解决方案。
EDIT: System info: RHEL5.1 64-bit using GNOME
编辑:系统信息:RHEL5.1使用GNOME 64位
7 个解决方案
#1
3
Any added ShutdownHooks
(more info here) should be executed by the JVM when terminated by SIGTERM
. Therefore, I think the problem is the way Eclipse is programmed to deal with such signals.
任何添加的ShutdownHooks(此处有更多信息)应由SIGTERM终止时由JVM执行。因此,我认为问题是Eclipse编程处理这些信号的方式。
As I don't know how the cleanup process is implemented in Eclipse, I can only assume that it is not called by any ShutdownHook
(and rather by an Action
or something similar).
由于我不知道如何在Eclipse中实现清理过程,我只能假设任何ShutdownHook都没有调用它(而是由Action或类似的东西调用)。
Edit: pidge has provided an answer below however which details steps which should allow you to shutdown Eclipse cleanly from the command line.
编辑:pidge在下面提供了一个答案,但是详细说明了应该允许您从命令行干净地关闭Eclipse的步骤。
#2
39
I figured this out with the help of gigi's answer and another question. You're going to need the wmctrl
and xdotool
utilities from your package manager.
我在gigi的回答和另一个问题的帮助下想出了这一点。您将需要包管理器中的wmctrl和xdotool实用程序。
Unless you're running in a terminal emulator on the same display, you need to set the right display:
除非您在同一显示器上的终端仿真器中运行,否则您需要设置正确的显示:
$ export DISPLAY=:0.0
Then (irrelevant windows elided from example):
然后(从示例中删除不相关的窗口):
# List windows
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
# Tell Eclipse window to close gracefully
$ wmctrl -c eclipse
# Darn, there's a confirmation dialog
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
0x03003c2d 0 kcirb Confirm Exit
# Find the window id
$ xdotool search Exit
Defaulting to search window name, class, and classname
50347053
# Send return key to the window
$ xdotool key --window 50347053 Return
Worked for me on Ubuntu 12.04, at least.
至少在Ubuntu 12.04上为我工作过。
EDIT: See Scarabeetle's answer for the tweaks you need to make it work from a script.
编辑:请参阅Scarabeetle的答案,了解使脚本运行所需的调整。
#3
7
Not enough reputation to comment on pidge's answer above... It almost works, but I needed to wait for some Gnome3 animation to finish and then give focus to the "Confirm Exit" window:
没有足够的声誉评论上面的pidge的答案...它几乎可以工作,但我需要等待一些Gnome3动画完成,然后将焦点放在“确认退出”窗口:
export DISPLAY=:0.0 # Do this in main X session
wmctrl -c "Eclipse SDK" # Close main window
sleep 1 # Wait for animation
wmctrl -a "Confirm Exit" # Give focus to the dialog
# Send a Return keypress to press the OK button
xdotool key --window $(xdotool search "Confirm Exit") Return
#4
3
Try killing java process(es). Do ps -ea | grep java
尝试杀死java进程。做ps -ea | grep java
#5
1
Did you tried with wmctrl? wmtrl -l lists the windows and wmlctrl -c -P should close the window. Anyway you could have problems with the confirmation dialog of eclipse.
你尝试过wmctrl吗? wmtrl -l列出了windows和wmlctrl -c -P应关闭窗口。无论如何,你可能会遇到eclipse确认对话框的问题。
#6
0
Did you try kill -HUP
(kill -1
)? -- that's the canonical way to tell a process that whoever was interacting with it has gone away and it should clean up appropriately
你有没有尝试杀死-HUP(杀死-1)? - 这是告诉流程任何与之交互的人已经消失的规范方式,它应该适当地清理
#7
0
The answer to this question was helpful to me in a similar issue: Eclipse hanging, how to kill it properly?
这个问题的答案在类似问题上对我有帮助:Eclipse挂起,如何正确杀死它?
After I killed the eclipse process the Eclipse window kept there until I killed the java process (I didn't have a javaw process as in the answer above. I had only one "java" process that when killed fixed the problem).
在我杀死eclipse进程之后,Eclipse窗口一直存在,直到我杀死了java进程(我没有像上面的答案那样有一个javaw进程。我只有一个“java”进程,当被杀死修复了这个问题)。
#1
3
Any added ShutdownHooks
(more info here) should be executed by the JVM when terminated by SIGTERM
. Therefore, I think the problem is the way Eclipse is programmed to deal with such signals.
任何添加的ShutdownHooks(此处有更多信息)应由SIGTERM终止时由JVM执行。因此,我认为问题是Eclipse编程处理这些信号的方式。
As I don't know how the cleanup process is implemented in Eclipse, I can only assume that it is not called by any ShutdownHook
(and rather by an Action
or something similar).
由于我不知道如何在Eclipse中实现清理过程,我只能假设任何ShutdownHook都没有调用它(而是由Action或类似的东西调用)。
Edit: pidge has provided an answer below however which details steps which should allow you to shutdown Eclipse cleanly from the command line.
编辑:pidge在下面提供了一个答案,但是详细说明了应该允许您从命令行干净地关闭Eclipse的步骤。
#2
39
I figured this out with the help of gigi's answer and another question. You're going to need the wmctrl
and xdotool
utilities from your package manager.
我在gigi的回答和另一个问题的帮助下想出了这一点。您将需要包管理器中的wmctrl和xdotool实用程序。
Unless you're running in a terminal emulator on the same display, you need to set the right display:
除非您在同一显示器上的终端仿真器中运行,否则您需要设置正确的显示:
$ export DISPLAY=:0.0
Then (irrelevant windows elided from example):
然后(从示例中删除不相关的窗口):
# List windows
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
# Tell Eclipse window to close gracefully
$ wmctrl -c eclipse
# Darn, there's a confirmation dialog
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
0x03003c2d 0 kcirb Confirm Exit
# Find the window id
$ xdotool search Exit
Defaulting to search window name, class, and classname
50347053
# Send return key to the window
$ xdotool key --window 50347053 Return
Worked for me on Ubuntu 12.04, at least.
至少在Ubuntu 12.04上为我工作过。
EDIT: See Scarabeetle's answer for the tweaks you need to make it work from a script.
编辑:请参阅Scarabeetle的答案,了解使脚本运行所需的调整。
#3
7
Not enough reputation to comment on pidge's answer above... It almost works, but I needed to wait for some Gnome3 animation to finish and then give focus to the "Confirm Exit" window:
没有足够的声誉评论上面的pidge的答案...它几乎可以工作,但我需要等待一些Gnome3动画完成,然后将焦点放在“确认退出”窗口:
export DISPLAY=:0.0 # Do this in main X session
wmctrl -c "Eclipse SDK" # Close main window
sleep 1 # Wait for animation
wmctrl -a "Confirm Exit" # Give focus to the dialog
# Send a Return keypress to press the OK button
xdotool key --window $(xdotool search "Confirm Exit") Return
#4
3
Try killing java process(es). Do ps -ea | grep java
尝试杀死java进程。做ps -ea | grep java
#5
1
Did you tried with wmctrl? wmtrl -l lists the windows and wmlctrl -c -P should close the window. Anyway you could have problems with the confirmation dialog of eclipse.
你尝试过wmctrl吗? wmtrl -l列出了windows和wmlctrl -c -P应关闭窗口。无论如何,你可能会遇到eclipse确认对话框的问题。
#6
0
Did you try kill -HUP
(kill -1
)? -- that's the canonical way to tell a process that whoever was interacting with it has gone away and it should clean up appropriately
你有没有尝试杀死-HUP(杀死-1)? - 这是告诉流程任何与之交互的人已经消失的规范方式,它应该适当地清理
#7
0
The answer to this question was helpful to me in a similar issue: Eclipse hanging, how to kill it properly?
这个问题的答案在类似问题上对我有帮助:Eclipse挂起,如何正确杀死它?
After I killed the eclipse process the Eclipse window kept there until I killed the java process (I didn't have a javaw process as in the answer above. I had only one "java" process that when killed fixed the problem).
在我杀死eclipse进程之后,Eclipse窗口一直存在,直到我杀死了java进程(我没有像上面的答案那样有一个javaw进程。我只有一个“java”进程,当被杀死修复了这个问题)。