Reputation: 1980
Removing unused import is one the best practices. While trying to follow it (Ctrl+Shift+O) I end up getting a lot of errors.
And then I need to resolve those via maven dependencies adding the jar or adding the dependency on the jar.
Eclipse gives me the option of using "Fix Project Setup". Clicking it prompts with a list of jars to add to the build path. How to know which one to use?
What things I can take care to avoid such things ?
Upvotes: 0
Views: 567
Reputation: 13057
Let's recap what you should have done. Maybe you've done it already, but just to make sure, there is nothing left:
This is how a project looks like, if the Maven support is not enabled (there is no "M" in the project's icon):
To enable Maven support, right-click on the project and enable Maven configuration:
Then you see the "M". Now dependencies managed by Maven are automatically recognized by the Eclipse project.
Adding dependencies is done in your pom.xml
file, such as:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myproject</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
Now you have the JUnit dependency in your project.
The dependency also appears in the Package Explorer:
You even see, that the project references one more library, this is because JUnit itself depends on this dependeny. It is recursive.
Upvotes: 2
Reputation: 3014
use maven command to resolve eclipse problems mvn clean install eclipse:clipse
if command is suucessful(build success) refresh workspace
Upvotes: 0