Eclipse organizes imports: how to choose JRE classes?

I actively use the Eclipse import function for the organization, but for me the big annoyance is the tendency to add some incredibly niche type from the dependency with the same name as the class from the JRE.

For example, when I declare a Map map; and run "organize import", Eclipse can add import net.some.dependency.of.my.dependency.i.never.use.Map instead of import java.util.Map , and then valuable time is wasted as I figure out why map.entrySet() no longer works.

Is there any way to impose a priority system on imports? For instance:

  • JRE Classes
  • My own classes
  • my addictions
  • dependencies of my dependencies (etc. for 5., 6., ...)

I am using Eclipse Neon 4.6.0M7.

PS: My dependencies are managed using Maven 3.3.9, if that matters.

+5
source share
2 answers

I don’t know about priority support, but you could just say that you are not interested in some types or packages on the Java / Appearance / Type filters preferences page. Types are not shown here using content.

eg. I never develop into AWT or Swing, so I disable them to support content, as seen in the screenshot Filter AWT and Swing from content

+3
source

I would carefully consider the Eclipse .classpath file in the project folder. If the classpath elements are ordered in some way, it is possible that this ordering is also controlled in the IDE options dialog box.

See What is in the Eclipse.classpath / .project file?

+1
source

All Articles