cb4
cb4

Reputation: 9353

How to prevent Eclipse from auto-importing packages?

My search first directed me to this SO question about pasting code. I followed that answer and went about my business, editing other code, etc. A short time later, I was surprised to see that Eclipse had again auto-imported statements in the original file. How can auto-imports be completely turned off?

Upvotes: 1

Views: 1465

Answers (1)

cb4
cb4

Reputation: 9353

In Eclipse: Window > Preferences > Java > Editor > Save Actions > uncheck Organize Imports. This globally affects all projects in your workspace.

If the annoying auto-import affects only a few projects, leave the global Organize Imports checked and, from the Preferences window, click on Configure Project Specific Settings... and uncheck Organize Imports. You can also get there by right-clicking a project, then Properties > Java > Editor > Save Actions > then check Enable project specific settings and uncheck Organize Imports.

There seems to be another option to stop auto-imports, depending on what is being imported. In the interest of providing a complete answer, I tested this in Eclipse 2019-06 (both global and project-specific settings). In Window > Preferences > Java > Code Style > Organize Imports, remove the entry an auto-import was associated with. For example, if the auto-import is in com.sun.org.apache.xml... then remove com. Theoretically, if Eclipse isn't managing any imports in com..., then it shouldn't auto-import com.sun.org.apache.xml.internal.utils.BoolStack. However, this setting didn't work to stop the auto-import.

Upvotes: 2

Related Questions