开发者

Can eclipse be configured to automatically fix missing Imports?

Because they didn't make it easy enough a开发者_高级运维lready ;)


I think you are looking for Ctrl + Shift + O

You can also set up Eclipse to automatically organize imports on save:

Preferences > Java > Editor > Save Actions


Eclipse: Automatically fix missing imports

1. macOS

a) Organize all imports

Command + Shift + O

b) Add import for a specific line

Command + Shift + M

2. Windows

a) Organize all imports

Control (Ctrl) + Shift + O

b) Add import for a specific line

Control (Ctrl) + Shift + M


Ctrl + Shift + O (Cmd + Shift + O for mac) - Organize all imports
Ctrl + Shift + M (Cmd + Shift + M for mac) - Import one by one (you need cursor on the red marker)


From Eclipse Menu, Select Source-->Organize Imports. This will remove all unused imports from that Java file.


@Fabian's answer is correct if the class to be imported is already on the classpath for the java project or plugin.

I'm not aware of a way to get Require-Bundle headers added(in the case of eclipse plugins) or package imports(in the case of osgi bundles) added automatically by Eclipse.

What this means is that you can get what you want as long as you restrict the classes you add to those already on the classpath. However, if you try to start using a class that isn't already on your path, the organize imports aren't going to be able to help you.


I found this site: http://eclipseone.wordpress.com/2010/03/10/navigate-and-fix-errors-amp-warnings-in-a-class-with-eclipse-keyboard-shortcuts/

It recommends using ctr/cmd + 1 to use the keyboard, this is much better than having to use the mouse, but I'm still looking for a "Just do the right thing most of the time" automatic solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜