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?
I
BuZZ-dEE
5,80512 gold badges66 silver badges95 bronze badges
asked Apr 3, 2013 at 18:10
3
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.
answered Oct 28, 2014 at 7:35
AKSAKS
6806 silver badges7 bronze badges
6
-
Right click your project name.
-
Click
Properties
. -
Click
Java Build Path
. -
Click on
Add Class Folder
. -
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).
answered Apr 3, 2013 at 18:16
KyleMKyleM
4,4158 gold badges46 silver badges78 bronze badges
7
To solve the error «…cannot be resolved to a type..» do the followings:
- Right click on the class and select «Build Path—>Exclude»
- Again right click on the class and select «Build Path—>Include»
It works for me.
answered Apr 21, 2016 at 10:51
0
There are two ways to solve the issue «cannot be resolved to a type
«:
- For non maven project, add jars manually in a folder and add it in java build path. This would solve the compilation errors.
- 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.
answered May 3, 2018 at 6:37
Swati GourSwati Gour
911 silver badge4 bronze badges
1
Project -> Clean
can at least sometimes be sufficient to resolve the matter.
answered Mar 12, 2018 at 18:47
JoolJool
1,68615 silver badges14 bronze badges
For maven users:
- Right click on the project
- Maven
- Update Project
answered Mar 17, 2017 at 15:44
1
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.
answered Sep 17, 2018 at 21:38
- 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
answered Jul 28, 2017 at 18:43
Prashanth SamsPrashanth Sams
19.2k20 gold badges101 silver badges125 bronze badges
Solved the problem by dropping the jar into WEB_INF/lib.
answered Sep 8, 2016 at 15:09
Andreas L.Andreas L.
2,77522 silver badges23 bronze badges
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
answered May 22, 2017 at 11:57
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
}
}
answered Aug 18, 2017 at 10:38
JamiscoJamisco
1,6133 gold badges13 silver badges17 bronze badges
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
answered Mar 20, 2018 at 14:20
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
answered Jun 4, 2018 at 10:56
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..
answered Nov 22, 2018 at 17:04
AnnuAnnu
5324 gold badges8 silver badges22 bronze badges
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
answered Apr 3, 2019 at 11:02
andronandron
241 silver badge11 bronze badges
I just closed all the files and reopened them, and voila!!! Hope this helps someone in the future
answered Jul 8, 2020 at 11:35
charlchadcharlchad
3,3231 gold badge15 silver badges9 bronze badges
Download servlet-api.jar file and paste it in WEB-INF folder it will work
answered Jan 6, 2021 at 6:41
1
Are you struggling with the «String Cannot be Resolved to a Type» error in your Java code? This error occurs when the Java compiler is unable to recognize the class or interface that the code is trying to reference. Fortunately, there are a few steps you can take to troubleshoot and resolve this error. In this guide, we’ll walk you through the troubleshooting process step-by-step.
Step 1: Check Your Imports
The first step in troubleshooting this error is to check your imports. Make sure that you have imported the correct packages and classes that your code is referencing. For example, if you are working with Strings, make sure that you have the following import statement at the top of your code:
import java.lang.String;
If you’re still experiencing the error after checking your imports, move on to step two.
Step 2: Check Your Classpath
The next step is to check your classpath. The classpath is a list of directories and JAR files that the JVM uses to search for classes and packages. If the class or package that your code is referencing is not in the classpath, you will see the «String Cannot be Resolved to a Type» error.
To check your classpath, open your project settings and navigate to the «Java Build Path» tab. Make sure that all the required JAR files and directories are included in the classpath.
Step 3: Clean and Rebuild Your Project
If you’ve checked your imports and classpath and are still experiencing the error, try cleaning and rebuilding your project. Sometimes, the error can occur due to a corrupted build or compiled file.
To clean and rebuild your project, navigate to the «Project» menu and select «Clean.» Select your project and click «OK.» Once the cleaning process is complete, navigate to the «Project» menu again and select «Build All.»
Frequently Asked Questions
Q: Can this error occur if I misspell a class or package name in my code?
A: Yes, if you misspell a class or package name in your code, the Java compiler will not be able to recognize it, and you will see the «String Cannot be Resolved to a Type» error.
Q: What should I do if the error still persists after following these steps?
A: If you’ve followed all the troubleshooting steps and are still experiencing the error, try restarting your IDE or computer. Sometimes, this can help resolve the issue.
Q: Can this error occur if I’m using an outdated Java version?
A: Yes, if you’re using an outdated Java version, you may encounter this error. Make sure that you’re using the latest version of Java.
Q: Can I use a wildcard (*) in my import statement to import all classes in a package?
A: Yes, you can use a wildcard in your import statement to import all classes in a package. For example:
import java.util.*;
Q: How can I avoid this error in the future?
A: To avoid this error in the future, make sure that you’re using the correct class and package names in your code, import the required packages, and keep your classpath up-to-date.
Conclusion
The «String Cannot be Resolved to a Type» error can be frustrating, but by following these troubleshooting steps, you can quickly identify and resolve the issue. Remember to check your imports, classpath, and clean and rebuild your project if necessary. If you’re still experiencing the error, try restarting your IDE or computer. With these tips in mind, you’ll be able to write Java code without encountering this error in the future.
- Java Build Path in Eclipse
- Classpath in Java
- Java String Class
So I’m coding along and all of a sudden, Eclipse (3.4) can’t resolve classes. Classes that are in the same package as the class I’m editing. Classes that are fully qualified in the import statement.
Not good.
The last thing I had done was add a Spring @Autowired annotation. I saved the file and voila, everything goes to crap. I then spend a stupid amount of time trying to track down the cause. I took the changes out. I did a clean and rebuild and retest (everything passed; this was Eclipse-only). I added new classes to see if they broke (they did). I did a false modify (add space, remove space, save) to see if that broke said file (it did). It was a death spiral. No matter how I changed the code, the same problem was there.
Turns out, it wasn’t the annotation, or anything else in Spring, or any of my code, or any of my Eclipse plugins. It was a step before that killed me. I was doing a little cleanup and I created a temp directory at the top of my project folder so I could move some files there. It wasn’t nested in anything, other than the top level directory. What could go wrong?
Apparently, that makes Eclipse see red. Squiggly red.
The solution was simply to do a refresh (F5) on my project. Just as quickly as it started, the problem went away. That smells like a bug to me, but if it was I figure I’d see a lot more mentions in Google or the Eclipse bug tracker. I’m really hoping this helps someone save some time.
Update: If that doesn’t work, try:
Clean, refresh, build, restart
Also, remember any external build/clean scripts you might be using. For instance, Grails has a command line “clean” you may have to invoke. Same if you have Ant or Maven builds.
David Resnick (comment below) discovered this tip for those with an external build script:
Windows–>Preferences–>Java–>Compiler–>Building–>Output folder–>”Rebuild class files modified by others”.
This exists in Eclipse 3.5; I’m not sure about earlier versions.
Another issue I’ve found over the years is problems when upgrading Eclipse. In theory, new versions of Eclipse should update your workspace and project files just fine. In practice, they can become corrupted. My new rule is to create a new workspace for every major version upgrade of Eclipse (maybe more often if you’re cautious). Then I copy those projects and import the copy. This ensures I have a backup plan should something go awry. You may need to reimport your project(s) if there’s a problem that won’t go away after an upgrade.
Many commenters offered other solutions, so check below. Thanks to those who contributed them!
Update: I switched to IntelliJ. Click that link for details why, it’s not the usual hand-wavy “it’s just so much better” that never got me to switch. Not saying it’s bug free, but nothing is, and I’ve never seen errors like this there.
Keywords: false error, bogus error, eclipse bug
[yjavac] 1. ERROR cannot be resolved to a type in Hybris?
Extensions can have dependencies on one another. While working with Hybris you come across a scenario, where you want to import a class from the different extension. The build only works if the required extension is available.
Ensure the below steps to works it smoothly.
Dependencies to Non-Platform(not located in /platform/ext
) Extension
- The required extension should be there in
localextensions.xml
- Add the required extension in
extensioninfo.xml
(e.g<requires-extension name="hmc"/>
) of the dependent extension -
In your eclipse(IDE), add required extension in
build path
of the dependent extension to resolve IDE dependecy.Note: Adding required extension in IDE build path won’t resolve extension dependency of your platform. It only resolved by
extensioninfo.xml
-
Rebuild the system (
ant clean all
)
Dependencies to Platform Extension
By default, all extensions have the dependency on Platform extension(located at /platform/ext
). Therefore, you do not required to specify requires-extension
for the Platform extensions in extensioninfo.xml
file.
Ankitkumar Patel
Sr. SAP Hybris consultant, having 10+ years experience in SAP Commerce Cloud (Hybris), Java, J2EE.
Extensive hands-on experience in SAP Hybris development, third-party integrations, project architecture and design… Read more
Popular posts from this blog
Hybris flexible search query examples
Use of Enum in the query Find all running Solr Index jobs select {cj.code},{enum:code},{cj.startTime},{cj.endTime} from { SolrIndexerCronJob! as cj join EnumerationValue as enum on {cj.status}={enum.pk} } where {enum:code} = ‘RUNNING’ Compare Date in the flexiblesearch query Find all running Solr Index jobs from the given date select {cj.code},{enum:code},{cj.startTime},{cj.endTime} from { SolrIndexerCronJob! as cj join EnumerationValue as enum on {cj.status}={enum.pk} } where {enum:code} = ‘RUNNING’ and {cj.startTime} >= TO_DATE(‘2021/12/25′,’YYYY/MM/DD’) Basic JOIN and IN query Get the most recent order for each customer using flexible search. select {o.code} as orderCode, {c.name} as name, {a.cellphone} as cellphone from {order as o join Customer as c on {c.pk} = {o.user} join Address as a on {o.deliveryaddress} = {a.pk} } where {o.code} in ({{select max({cod
How to remove or update all data records in Hybris?
Scenario 1: I want to remove all the data from the Hybris ItemType. Solution: If you want to remove all records for particular itemType. Then you can do it using HAC Impex import. Open HAC (/hac) Go to console > ImpEx Import Run the below Impex (Change MyItemType with the ItemType for which you want to remove the data) $targetType=MyItemType REMOVE $targetType[batchmode=true];itemtype(code)[unique=true] ;$targetType Scenario 2: Sometimes, you want to remove selected data based on some condition or probably want to run complex SQL query. Then we wish if we could do it by writing SQL query, as many of developers are aware of syntax and its resources are easily available. Solution: Yes, you can do it in Hybris HAC also. Only thing is you should know the appropriate table and attribute/fields names in DB. If you don’t, you can always run the select flexible search query and can see generated SQL query. Open HAC (/hac) Go to console > FlexibleSearch Se
How to Install temporary Hybris license?
LICENSE VERIFICATION HAS FAILED! Your demo/develop license has expired, it is valid only for 30 days. How to install temp SAP Hybris license? Don’t worry, you can install a temporary license. To install a temporary license 1) Remove installedSaplicenses.properties from the license folder hybrisconfiglicence 2) Go to the Platform directory and run the ./license.sh -temp CPS_SQL or license.bat -temp CPS_SQL . If you are using DB other than HSQL you can choose the right command based on your DB. Windows run license.bat instead of ./license.sh OOTB HSQL DB ./license.sh -temp CPS_SQL MySQL DB ./license.sh -temp CPS_MYS Oracle DB ./license.sh -temp CPS_ORA SQL Server DB ./license.sh -temp CPS_MSS SAP Hana DB ./license.sh -temp CPS_HDB Once you install using the above command, You will get a message like First temporary license key installed. 3) Verify your license by running ./license.sh -show , which will give you System, Hardwar
If you are seeing an error in Eclipse that says «cannot be resolved to a type,» it usually means that Eclipse is unable to find the class or interface that you are trying to use in your code. There are a few common causes for this error:
-
Typo: Make sure that you have spelled the class or interface name correctly and that it matches the spelling in the import statement (if you are using one).
-
Missing import: If you are using a class or interface from a package that is not part of the Java language, you will need to include an import statement at the beginning of your code to tell Eclipse where to find it. Make sure that you have the correct import statement for the class or interface that you are trying to use.
-
Classpath issue: If you are using a class or interface that is part of a library or external jar file, make sure that the library or jar file is on your Eclipse classpath. You may need to add it to your project’s build path or to the global classpath.
If you are still having trouble, try doing a clean build of your project (Project > Clean) and see if that resolves the issue. If the problem persists, you may need to check for any syntax errors or other issues in your code.