How to cleanly shutdown Eclipse from Linux command line?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6391705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:36:00  来源:igfitidea点击:

How to cleanly shutdown Eclipse from Linux command line?

linuxeclipsecommand-linekillworkspace

提问by Maian

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.

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.

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.

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.

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.

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.

EDIT: System info: RHEL5.1 64-bit using GNOME

EDIT: System info: RHEL5.1 64-bit using GNOME

采纳答案by vehk

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.

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.

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 Actionor something similar).

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 Actionor something similar).

Edit: pidge has provided an answer belowhowever which details steps which should allow you to shutdown Eclipse cleanly from the command line.

Edit: pidge has provided an answer belowhowever which details steps which should allow you to shutdown Eclipse cleanly from the command line.

回答by gigi

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.

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.

回答by Chris Dodd

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

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

回答by pidge

I figured this out with the help of gigi's answerand another question. You're going to need the wmctrland xdotoolutilities from your package manager.

I figured this out with the help of gigi's answerand another question. You're going to need the wmctrland xdotoolutilities from your package manager.

Unless you're running in a terminal emulator on the same display, you need to set the right display:

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

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 

# Send return key to the window
$ xdotool key --window 0x03003c2d Return

Worked for me on Ubuntu 12.04, at least.

Worked for me on Ubuntu 12.04, at least.

EDIT: See Scarabeetle's answerfor the tweaks you need to make it work from a script.

EDIT: See Scarabeetle's answerfor the tweaks you need to make it work from a script.

回答by Scarabeetle

Not enough reputation to comment on pidge's answerabove... It almost works, but I needed to wait for some Gnome3 animation to finish and then give focus to the "Confirm Exit" window:

Not enough reputation to comment on pidge's answerabove... It almost works, but I needed to wait for some Gnome3 animation to finish and then give focus to the "Confirm Exit" window:

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

回答by Sriram Bhargav Karnati

Try killing java process(es). Do ps -ea | grep java

Try killing java process(es). Do ps -ea | grep java

回答by user3131978

The answer to this question was helpful to me in a similar issue: Eclipse hanging, how to kill it properly?

The answer to this question was helpful to me in a similar issue: Eclipse hanging, how to kill it properly?

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

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