如何关闭 Eclipse 警告“从未使用过导入”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5005538/
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-09-19 15:47:29  来源:igfitidea点击:

How to turn off Eclipse warning "The import is never used"?

eclipseeclipse-pluginwarnings

提问by IAdapter

I have a lot of this warnings in project and I would like to turn it off. I'm not interested in removing those imports, so pleasedon't tell me how to do it.

我在项目中有很多这样的警告,我想将其关闭。我对删除这些导入不感兴趣,所以不要告诉我该怎么做。

I'm using eclipse 3.4.2.

我正在使用 Eclipse 3.4.2。

回答by Isaac Truett

To change for the entire workspace:

要更改整个工作区:

Window > Preferences > Java > Compiler > Errors/Warnings > Unused Import > Ignore.

窗口 > 首选项 > Java > 编译器 > 错误/警告 > 未使用的导入 > 忽略。

To override workspace settings for a single project:

要覆盖单个项目的工作区设置:

Project > Properties > Java Compiler > Errors/Warnings > Unused Import > Ignore.

项目 > 属性 > Java 编译器 > 错误/警告 > 未使用的导入 > 忽略。

回答by vickirk

@SuppressWarnings("unusedImports") disables just unused imports as opposed to al unused items

@SuppressWarnings("unusedImports") 仅禁用未使用的导入,而不是所有未使用的项目

回答by Tuukka Lindroos

Btw, one very good shortcut is ctrl+shift+o that cleans those imports automatically.

顺便说一句,一个非常好的快捷方式是 ctrl+shift+o 可以自动清除这些导入。

Also it is possible to put so that in every save imports are automatically organised from:

也可以放置以便在每个保存中自动组织导入:

window->preference->java->editor->save actions

If you prefer to leave those imports there, it is ok. But that is to anyone else :)

如果您希望将这些进口留在那里,那也没关系。但那是给其他人的:)

Also I am not sure about 3.4 version.

我也不确定 3.4 版本。

回答by clankill3r

If you have a file org.eclipse.jdt.core.prefsthen you can add org.eclipse.jdt.core.compiler.problem.unusedImport=ignore.

如果你有一个文件,org.eclipse.jdt.core.prefs那么你可以添加org.eclipse.jdt.core.compiler.problem.unusedImport=ignore.

When using vscode this file should be seen from the project root in a folder .settings.

使用 vscode 时,应该从文件夹中的项目根目录中看到此文件.settings