Eclipse error ... cannot be resolved to a type

JavaEclipse

Java Problem Overview


I have a dynamic web project that I am working on to migrate a jsp/servlet app from JRun to Tomcat.

I am getting the error: com.ibm.ivj.eab.dab.DatastoreJDBC cannot be resolved to a type.

I have the *.class files sitting inside a com/ibm/ivj/eab/dab folder (exactly how I found them). I have tried creating a jar file and adding that to the build path via "Add External Jar", I have also tried adding an "External Class Folder" and pointing to the folder that contains the "com" directory in question.

Still, the error persists. What is strange is if I start typing the package name eclipse actually auto-completes the class for me! (pictured below). Any ideas would be greatly appreciated. Maybe the classes were compiled for a much older java version and that is causing trouble? Maybe there is something I need to do to ensure the classes end up in the WEB-INF/lib directory?

Ienter image description here

Java Solutions


Solution 1 - Java

Also If you are using mavenised project then try to update your project by clicking Alt+F5. Or right click on the application and go to maven /update project.

It builds all your components and resolves if any import error is there.

Solution 2 - Java

  1. Right click your project name.

  2. Click Properties.

  3. Click Java Build Path.

  4. Click on Add Class Folder.

  5. Then choose your class.

Alternatively, Add Jars should work although you claim that you attempted that.

Also, "have you tried turning it off and back on again"? (Restart Eclipse).

Solution 3 - Java

To solve the error "...cannot be resolved to a type.." do the followings:

  1. Right click on the class and select "Build Path-->Exclude"
  2. Again right click on the class and select "Build Path-->Include"

It works for me.

Solution 4 - Java

Project -> Clean

can at least sometimes be sufficient to resolve the matter.

Solution 5 - Java

There are two ways to solve the issue "cannot be resolved to a type ":

  1. For non maven project, add jars manually in a folder and add it in java build path. This would solve the compilation errors.
  2. For maven project, right click on the project and go to maven -> update project. Select all the projects where you are getting compilation errors and also check "Force update of snapshots/releases". This will update the project and fix the compilation errors.

Solution 6 - Java

For maven users:

  • Right click on the project
  • Maven
  • Update Project

Solution 7 - Java

Easy Solution:
Go to

> Project property -> java builder path -> maven -> find c3p0-0.9.5.2.jar

and see the location where the file is stored in the local repository and go to this location and delete the repository manually.

G

Solution 8 - Java

  • Right click Project > Properties
  • Java Build Path > Add Class Folder
  • Select the bin folder
  • Click ok
  • Switch Order and Export tab
  • Select the newly added bin path move UP
  • Click Apply button

enter image description here

Solution 9 - Java

Solved the problem by dropping the jar into WEB_INF/lib.

Solution 10 - Java

copying the jar files will resolve. If by any chance you are copying the code from any tutorials, make sure the class names are spelled in correct case...for example i copied a code from one of the tutorials which had solr in S cap. Eclipse was continiously throwing the error and i also did a bit of googling ...everything was ok and it took 30 mins for me to realise the cap small issue. Am sure this will help someone

Solution 11 - Java

For many new users don't forget to add an asterisk (*) after your import statements if you wanna use all the classes in a package....for example

import java.io.*;

public class Learning 
{
	public static void main(String[] args) 
	{
		BufferedInputStream sd = new BufferedInputStream(System.in);
            // no error
	}
}

================================================================

import java.io;

public class Learning 
{
	public static void main(String[] args) 
	{
		BufferedInputStream sd = new BufferedInputStream(System.in);
            // BufferedInputStream cannot be resolved to a type error
	}
}

Solution 12 - Java

Solution : 1.Project -> Build Path -> Configure Build Path

2.Select Java Build path on the left menu, and select "Source"

3.Under Project select Include(All) and click OK

Cause : The issue might because u might have deleted the CLASS files or dependencies on the project

Solution 13 - Java

Project -> Build Path -> Configure Build Path
Select Java Build path on the left menu, and select "Source"
 click on Excluded and then Include(All) and then click OK
    Cause : The issue might because u might have deleted the CLASS files 
 or dependencies on the project

For maven users:

Right click on the project

Maven

Update Project

Solution 14 - Java

First you need to update the pom.xml by adding below

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.6.RELEASE</version>
	</dependency>

1] Right click your project name.

2] Click Properties.

3] Click Java Build Path.

4] Check on 'Maven Dependencies' in Order and Export tabl.

In my case, previously it was not enabled. So when I enabled it my @GetMapping annotation works fine..

Solution 15 - Java

Also, there is the solution for IvyDE users. Right click on project -> Ivy -> resolve It's necessary to set ivy.mirror property in build.properties

Solution 16 - Java

I just closed all the files and reopened them, and voila!!! Hope this helps someone in the future ;)

Solution 17 - Java

Download servlet-api.jar file and paste it in WEB-INF folder it will work

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmikeyView Question on Stackoverflow
Solution 1 - JavaAKSView Answer on Stackoverflow
Solution 2 - JavaKyleMView Answer on Stackoverflow
Solution 3 - JavaAmit Kumar DasView Answer on Stackoverflow
Solution 4 - JavaJoolView Answer on Stackoverflow
Solution 5 - JavaSwati GourView Answer on Stackoverflow
Solution 6 - JavaPaulo RodriguesView Answer on Stackoverflow
Solution 7 - JavaNazrul Islam RiadView Answer on Stackoverflow
Solution 8 - JavaPrashanth SamsView Answer on Stackoverflow
Solution 9 - JavaAndreas L.View Answer on Stackoverflow
Solution 10 - JavaHarish NarayananView Answer on Stackoverflow
Solution 11 - JavaJamiscoView Answer on Stackoverflow
Solution 12 - JavasundersparksView Answer on Stackoverflow
Solution 13 - JavaDevendra SingraulView Answer on Stackoverflow
Solution 14 - JavaAnnuView Answer on Stackoverflow
Solution 15 - JavaandronView Answer on Stackoverflow
Solution 16 - JavacharlchadView Answer on Stackoverflow
Solution 17 - JavaBinson SelvinView Answer on Stackoverflow