Vishwanath Krishnamurthi's blog

A blog on Java EE, clean code, open source and TDD

Resolving classpath issues with Eclipse + Maven

leave a comment »

Try Editing :

In a project directory, if some file-patterns are excluded from the classpath and you want to include them, you can do it this way :

Right-Click the project –> Build Path –> Configure Build Path –> Source Tab –> Choose the file-patterns you want to include –> Click edit.

The dialog-box would look like this

The same dialog-box helps you to exclude file-patterns.

For eg:

In the above image, all files in src/main/resources are ignored    (Pattern: **)

Select that pattern and click remove to include all. When it shows (None), there’s no exclusion pattern and

all files in the directory are included.

Try Regenerating :

If that doesn’t work, or your classpath problem isn’t that obvious, try regenerating the .classpath file.

Here’s how you can do it:

( But before going on, do take backup of  .classpath, .project files and .settings folder )

If you are using M2Eclipse:

Step 1:

Right-Click on the project –> Maven –> Disable Dependency Management

Step 2:

Right Click on the project –> Maven –> Enable Dependency Management

This way, M2Eclipse re-generates the .classpath file

If you are not using M2Eclipse:

Step 1:

Go to the root directory of the project and delete .classpath, .settings and .project
(Now its not an eclipse project anymore.. )

Step 2:
Run this command to make it an eclipse project again:

mvn eclipse:eclipse

Step 3:

Refresh the project in your workspace.

Now the .classpath file is built by reading M2_REPO classpath variable, which  is not defined in eclipse by default.
Check here to see how to add M2_REPO classpath variable to eclipse

Advertisements

Written by Vishwanath Krishnamurthi

May 5, 2011 at 6:43 am

Posted in Tools

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: