java eclipse red exclamation mark - java

I have just got a new computer and installed Eclipse Indigo and all of the plugins that I use. But when I open my workspace from my old computer some projects have an exclamation mark.
What does a red exclamation mark mean on a project folder?

The red exclamation mark usually means there is a problem with the Build Path.
Do you see any alerts in the "Problem" View?

It means that there is an error on that project..
You can look at all the errors in the Problems tab. press ALT SHIFT Q followed by X to
show this tab.

It means that there are two things happened.........
What ever jar file or project setup jar file for your application
are not located at that point where it was earlier in your computer.
So that First you have to setup your project with all the jar files
and refresh it.
Check syntax in your project might be some mistake in that.

The red exclamation mark in eclipse is because of the problem/issue with the build path.
To find the specific issue look at the problems tab of the eclipse.
Window -> Show View -> Problems (or) Alt+Shift+Q,X

If you didn't find any error on the project files, usually it means your build path has some issue. First Check your jar file and jar file locations.
On eclispe, right click on your project, Go to build path and go to Configure build path. Check any errors under libraries. Configure it correctly and refresh the project.

It appears mostly because of "build path" only. But just in case you are working on a MAVEN project, here is the solution.
Solution
Step 1. Expand your project in Eclipse > Right click on "JRE System Library" > "Build Path" > "Remove From Build path"
Step 2. Expand your project in Eclipse > Right click on "Maven Dependencies" > "Build Path" > "Remove From Build path"
Step 3. Reach out to your local repository and follow below path "C:\Users\userName\.m2\repository" and delete everything inside repository folder
Step 4. Refresh your project in Eclipse
Step 5. Right Click on your project > "Maven" > "Update Project"
Step 6. Just refresh your project and now we are Ready to GO..

In my case show hidden files was enabled and i had added hidden jar file extensions along with the original jars. Adding only the jar files except the hidden files solved the problem

It can appear when any other file other than .jar is added in the jar library. To fix this, remove the file and clean the project.

If it is maven project and your project view having no error. Then try the following steps
Right click the project ---> maven --> update maven
It works for me.

What the error means is that the Java (JDK) version installed needs an update, as the older version could not be read. To rectify the issue, uninstall your Java (JDK) and install the latest version. Restart eclipse and the would be seen resolved.

This may help in case your build path is correct and you have put the right signature and access specifier for main, so maybe used as a hook to try before you make any modifications to your build path.
Just go to your problems bar and delete the problem given for the project, clean the project and build it. It should solve the problem, if these steps cause the red exclamation to go away.

Related

main Class won't load on a different computer [duplicate]

I have a project in eclipse on my laptop that I pushed to Git https://github.com/chrisbramm/LastFM-History-Graph.git
It works fully on my laptop and runs/builds without a problem but on my desktop it doesn't Eclipse gives the error
Error: Could not find or load the main class lastfmhistoryguis.InputPanel
I've tried building the project from:
Project>Build Project
But nothing happened. I've set the PATH variables on this computer to JRE6, JRE7 and JDK 1.7.0 even though these aren't set on my laptop.
I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:\Users\Chris\Downloads folder on my laptop hence it wasn't included in the git tree which I recently brought into the project folder and committed ,but I'm not sure whether I have done it right.
Would this also be causing a problem but there isn't a main argument in there.
I can't work out now, what I need to check/change.
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
tl;dr:
Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.
Project -> Clean
Make sure Project -> Build automatically is active
Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.
Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.
In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.
If this is still not working, have a look at the built-in ErrorLog of Eclipse:
Window -> Show View -> General -> Error Log
In your classpath you're using an absolute path but you've moved the project onto a new machine with quite possibly a different file structure.
In your classpath you should therefore (and probably in general if you're gonna bundle JARS with your project), use relative pathing:
In your .classpath
change
<classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/><classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/>
to
<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>
I did all the things mentioned above, but none of them worked for me
My problem resolved as follows:
Right click on your Project > Properties > JavaBuildPath > Libraries.
Remove the jar file, having a red flag on it.
If problem persists try the solution below. This worked for me when I faced this problem second time:
Right-Click Project > Properties > Java Build Path > Libraries
Remove Library
Add Library. (Choose the JRE System Library )
I faced similar problem in my maven webapp project after spending nearly one hour , I found a solution which worked for me .I typed the following maven command and It worked
mvn clean install -U
I dont know the exact reason behind it.
I am assuming that you had imported the project into your desktop eclipse installation? If that is the case, you should just select Project > Clean. Then rebuild your project. Worked like a charm for me.
VERY CAREFUL: This will unbind your project from the workspace. You'll have to import all your projects again
I had the same issue and solved it using:
Eclipse Mars
Egit
Github
Maven Project
The Problem was that i made my maven project available to github. It moved my project to my github folder.
Solution:
Close Eclipse
Delete the metadata folder inside your workspace
Restart Eclipse
Start screen will be displayed.
Close the start screen
Rightclick into package explorer
Chose "import maven project",
Navigate to your github folder and import the maven project.
After this my project compiled with success.
Check that your project has a builder by either:
check project properties (in the "package explorer", right click on the project, select "properties"), there the second section is "Builders", and it should hold the default "Java Builder"
or look in the ".project" file (in .../workspace/yourProjectName/.project) the section "buildSpec" should not be empty.
There must be other ways, but what I did was:
shut down eclipse
edit the ."project" file to add the "buildSpec" section
restart eclipse
A proper minimal java ".project" file should look like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Well the following worked for me...
Went into the project folder (inside workspace)
Then, deleted the bin folder
Then, Cleaned project / projects (in Eclipse)
built/run from Eclipse.
If your code is good and you know you're having an Eclipse problem, this will solve it.
You could simply delete $yourproject/.classpath , $yourproject/.project , and $yourworkspace/.metadata. Someone else mentioned this option. It will blow up your entire workspace though. Instead:
Delete .classpath and .project from your project
Delete your project in eclipse. DO NOT check delete project
contents on disk.
Now, in a file explorer, go into $yourworkspace/.metadata.
Search for $yourprojectname
Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
Right click your project > properties > Java Build Path > Source tab
Select all source folders, remove.
Add folder, select src (whatever your src folder is called) and add it
Go to libraries tab
Add any jars to your build path here. There should be no more errors on your project now.
Run your project like you normally would.
Similar thing happened to me few times, the only way I knew to fix this was to remove the metadata folder. Fortunately I have found another way.
Try going to project properties > Java Build Path > Order And Export tab > select all (or try to play with check boxes there).
This should cause complete project rebuild and Eclipse to see main class.
Addition: I have noticed that this bug occurs when you have many projects in a work space and some of them is configured wrong(red exclamation mark appears). Fixing project build path and other settings(even if this project is not related to the one you have problems with) should fix an issue.
For me, the reason that this error started showing up was due to classpath getting over the limit on windows. Then I discovered the option "Use temporary JAR to specify classpath (to avoid classpath length limitations)". Selecting this option fixed the problem for me. The option resides in Run/Debug Configuration, Classpath tab, see the image below.
My Main class could not be found or loaded problem is caused by an interesting reason.
In our project, we are using Maven as build tool and my main class extends a class, which is on the class path but its scope was test, while the main class is not under the test package.
If your main class extends a class, first try to run your main class by removing extends part. If it runs, you will at least understand that the problem is not because of run configuration or eclipse but the class, your main class extends.
this could cause of jdk libraries if you had imported into jre
this happen to me , so check installed jre jars
in eclipse click on Windows > Preferences > Java > Installed Jres > click on Jre and edit after that look into jar list make sure none is of jdk or corrupted ,
I had the same problem with correct .classpath file, and soon found actually it's not the .classpath file counted (after I fixed this issue, I replace the workable .classpath file with the original one, the project still worked, which means the .classpath file was not the case)
Since it's a Maven project, all I did is:
mvn eclipse:clean
delete eclipse project
import the project
done
This problem is also caused when you have special characters in your workspace path. I had my workspace in my personal folder and its name was in Greek, so it didn't work. I changed my workspace, now contains only english characters in its path, and now the project is built without any problems.
If You are using eclipse then the following steps will solve your problem:
Go to Run -> Run Configurations -> Main Class Search -> Locate your class manually -> Apply -> Run
I had this error. It was because I had
static void main(String[] args)
instead of
public static void main(String[] args)
I spent nearly an hour trying to figure that out.
Note: The only difference is that I didn't declare main to be public
To solve this error do the following steps:
Step 1: Open the .project file.
Step 2: Check two tags...
a) <buildSpec>
b) <natures>
Step 3: If the above-mentioned tags do not include any content then surely the above error is going to occur.
Step 4: Add the following content to each tag in order to resolve the above error.
For <buildSpec> :
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
For <natures> :
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Step 5: Save your file by hitting ctrl + s.
Step 6: For safe side just close the project once and reopen it.
Step 7: That's it. You are ready to rock!!!
Please mention in comments if the solution was helpful.
Thank you.
I run into the same problem, but in my case it was caused by missing (empty) source folder (it exists in original project, but not in GIT repository because it's empty).
After creating the missing folder everything works.
I ran into this error today because I set up a hello world program and then cut and pasted a new program into the same file. To fix the problem of not finding hello world as the last was called I clicked Run-> Run Configurations and then under Main Class I clicked search and it found my new class name and replaced it with the correct new name in the text that I pasted. This is a newbie problem I know but it is also easy to fix. I hope this helps someone!
Douglas
Mostly this happens, because Eclipse cleans the .class files, but don't build them again. Check the bin folder, it should be empty. Then you should check, is there anything else, which is causing build ti fail. You might have added some jars in classpath, which Eclipse might not be able to find.
Just go to your Package Explorer and press F5, or for some laptops fn+F5. The reason is that eclipse thinks that the files are somewhere, but the files are actually somewhere else. By refreshing it, you put them both on the same page. Don't worry, you won't lose anything, but if you want to be extra careful, just back up the files from your java projects folder to somewhere safe.
These are the simple steps, which helped me to solve this problem.
Close the eclipse
Delete ".metadata" folder in your work-space. (may be hidden folder)
Open the eclipse (it will automatically create ".metadata" folder in your work- space)
Try to run the program.
Check the workspace error log (Windows-> Show View -> Error log). If you see any of the jar's imported is corrupted, remove the corresponding repository folder and re-import again.
2 types of solutions exits for the same.
(1) Go to run configurations: - run->run configurations
In the Classpath tab:
Select Advanced
Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
(2) If first solution is not working then it means the jar you are pointing out to your project is taking the path of your local Maven repo which is not getting updated to your project so better you check the jar from that local maven repo and copy it paste it into new project simply or just download it from any site and configure it into your build path.
I hope it helps.
This problem occurred for me when I deleted a ".jar" file from Eclipse project by right clicking on it and hitting "delete" (not from "Build path").
To solve, I tried the following steps:
1- Right click on the project
2- Build Path --> Configure Build Path
3- Libraries
4- Delete the jar file from there (I see a red mark beside it).
I received this error as well, just after moving some resources. Checking the error log, I saw that Eclipse couldn't make a build since it couldn't remove a file/folder. Try manually removing the "bin" (or whatever it's called for you) folder.
Can be resolved by updating your project.
For example if you use maven and eclipse as you mentioned, do those steps:
Right click on your project
Click on Maven
Click on Update Project...
Click Ok
I just had this problem after first having the problem of Windows 8 refusing to update my path no matter what I set JAVA_HOME to - java -version reported the last JDK instead of the one I stored in JAVA_HOME. I finally got that to work by putting '%JAVA_HOME%/bin;' at the front of the path environment variable instead of at the end. Then I launched Eclipse and all the sudden it could not find my main class when it worked fine before this. What I did to fix it was went into the project properties, removed the existing JRE library from the libraries tab, added a new JRE by selecting the "Add Library" button and then followed the prompts to install JRE 7 as my default JRE. Now all is back to working.

Could not find or load main class in STS/Eclipse

I have a main method in a package in one of my projects. Say, the package is com.ant.car. I am trying to run and/or debug this main method, and I keep getting the error Could not find or load main class com.ant.car.
I've searched this problem, and it seems like I can't figure out what is wrong.
1) I've checked run configurations. In Run->Run Configurations, I've checked that the Main class is com.ant.car.
2) I've checked build path. If I right click on the project, I select Build->Build Path, and under the Libraries tab I make sure there are no missing folders with red Xs next to them.
Not really sure what else to do. Any suggestions?
Project -> Clean
this is working
Try updating project by right clicking on it. Maven -> Update Project
Today I ran into the same problem and I tried a lot of answers. Nothing helped. Cleaning the project, build automatically is already checked, deleting .metadata, etc.
Eventually I tried this and it worked perfectly:
menu Project -> Properties
Java Build Path, tab Libraries
Remove the JRE System Library from there, press Add Library, take the JRE System Library and press Next. Workspace default JRE and press Finish.
What worked for me:
Menu Project -> Properties
In Java Build Path, tab Libraries
Delete all libraries with a red [x] next to them.
In my case, problem happened when I switched from Kepler to STS IDE.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
Sometimes the problem can be caused by some newly added dependencies. Try removing the recently added jars. That's how I fixed my problem.
Project -> Clean... -> check project not working -> Clean
I already had build automatically set, but forcing STS to rebuild it fixed it.
This issue occurs when the main .class file moved or not found because you changed the directory for committed/shared the project into the git or another repository.
To Resolve this issue -->
Remove existing run configuration and new one.
Find the parent pom.xml or project pom.xml and open cmd/command prompt and run the below commands,
mvn clean install package
mvn eclipse eclipse
It worked for me:
1. Delete metadata from work-space directory.
2. Import the project again, but selected copy to work-space option.
I think the cause for the error was Non-English characters in the original saved directory.
You just need to delete Run Configuration file and restart STS and run command -mvn clean install and try to restart the service
The Error "Could not find or load main class com.ant.car" occur when your class is not in build path. please make sure that .class file is generated and it's in build path ..
I faced the same issue..
just do follow these steps:
STS/Eclipse --> Project --> Enable "Build Automatically"
then refresh your project, it will resolve your issue.
Still not refreshed your projects automatically, just restart your STS and check.
Hope it will help you.
I think .class files are deleted/missing from JavaProject/bin folder.
To resolve this issue ->
1) Just cut paste and save the code contents of all the files that you are using then .class files will be regenerated.
2) Then run the code and you can see it works fine if there is no syntactical errors.
1 ) Clean the Project
2 ) Enable build automatically Option
3 ) Update the maven project by use the short cut Alt + F5
Deleting target folder manually and mvn clean install worked for me
A quick and easy fix is to directly run your SpringBootApplication class (i.e. Right click, Run As -> Spring Boot App). This runs the app and creates a run configuration automatically.
I spent several hours on this issue, finally it is fixed by doing this:
Properties -> Java Compiler: uncheck the checkbox "use '--release' option"
This worked for me to solve the error. (I got this error after removing AWS ToolKit)
Close the Eclipse/ STS Eclipse.
Go to the WorkSpace folder.
Delete the .metadata folder.
Open the eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Remove project from STS/Eclipse
Close or Refresh the Eclipse/ STS Eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Tried above mentioned steps to resolved issue.
You can try one of the two solutions below:
Solution 1: Right click the project -> Gradle -> Refresh Gradle Project.
Solution 2: Add gradle or maven in your environment variable. My problem was that I had not added gradle in my environment variable. Before, make sure Gradle or maven is installed in your OS.
I tried all the answers but finally what worked for me was deleting the project from eclipse workspace and importing it again.

Eclipse "Error: Could not find or load main class"

I have a project in eclipse on my laptop that I pushed to Git https://github.com/chrisbramm/LastFM-History-Graph.git
It works fully on my laptop and runs/builds without a problem but on my desktop it doesn't Eclipse gives the error
Error: Could not find or load the main class lastfmhistoryguis.InputPanel
I've tried building the project from:
Project>Build Project
But nothing happened. I've set the PATH variables on this computer to JRE6, JRE7 and JDK 1.7.0 even though these aren't set on my laptop.
I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:\Users\Chris\Downloads folder on my laptop hence it wasn't included in the git tree which I recently brought into the project folder and committed ,but I'm not sure whether I have done it right.
Would this also be causing a problem but there isn't a main argument in there.
I can't work out now, what I need to check/change.
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
tl;dr:
Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.
Project -> Clean
Make sure Project -> Build automatically is active
Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.
Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.
In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.
If this is still not working, have a look at the built-in ErrorLog of Eclipse:
Window -> Show View -> General -> Error Log
In your classpath you're using an absolute path but you've moved the project onto a new machine with quite possibly a different file structure.
In your classpath you should therefore (and probably in general if you're gonna bundle JARS with your project), use relative pathing:
In your .classpath
change
<classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/><classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/>
to
<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>
I did all the things mentioned above, but none of them worked for me
My problem resolved as follows:
Right click on your Project > Properties > JavaBuildPath > Libraries.
Remove the jar file, having a red flag on it.
If problem persists try the solution below. This worked for me when I faced this problem second time:
Right-Click Project > Properties > Java Build Path > Libraries
Remove Library
Add Library. (Choose the JRE System Library )
I faced similar problem in my maven webapp project after spending nearly one hour , I found a solution which worked for me .I typed the following maven command and It worked
mvn clean install -U
I dont know the exact reason behind it.
I am assuming that you had imported the project into your desktop eclipse installation? If that is the case, you should just select Project > Clean. Then rebuild your project. Worked like a charm for me.
VERY CAREFUL: This will unbind your project from the workspace. You'll have to import all your projects again
I had the same issue and solved it using:
Eclipse Mars
Egit
Github
Maven Project
The Problem was that i made my maven project available to github. It moved my project to my github folder.
Solution:
Close Eclipse
Delete the metadata folder inside your workspace
Restart Eclipse
Start screen will be displayed.
Close the start screen
Rightclick into package explorer
Chose "import maven project",
Navigate to your github folder and import the maven project.
After this my project compiled with success.
Check that your project has a builder by either:
check project properties (in the "package explorer", right click on the project, select "properties"), there the second section is "Builders", and it should hold the default "Java Builder"
or look in the ".project" file (in .../workspace/yourProjectName/.project) the section "buildSpec" should not be empty.
There must be other ways, but what I did was:
shut down eclipse
edit the ."project" file to add the "buildSpec" section
restart eclipse
A proper minimal java ".project" file should look like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Well the following worked for me...
Went into the project folder (inside workspace)
Then, deleted the bin folder
Then, Cleaned project / projects (in Eclipse)
built/run from Eclipse.
If your code is good and you know you're having an Eclipse problem, this will solve it.
You could simply delete $yourproject/.classpath , $yourproject/.project , and $yourworkspace/.metadata. Someone else mentioned this option. It will blow up your entire workspace though. Instead:
Delete .classpath and .project from your project
Delete your project in eclipse. DO NOT check delete project
contents on disk.
Now, in a file explorer, go into $yourworkspace/.metadata.
Search for $yourprojectname
Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
Right click your project > properties > Java Build Path > Source tab
Select all source folders, remove.
Add folder, select src (whatever your src folder is called) and add it
Go to libraries tab
Add any jars to your build path here. There should be no more errors on your project now.
Run your project like you normally would.
Similar thing happened to me few times, the only way I knew to fix this was to remove the metadata folder. Fortunately I have found another way.
Try going to project properties > Java Build Path > Order And Export tab > select all (or try to play with check boxes there).
This should cause complete project rebuild and Eclipse to see main class.
Addition: I have noticed that this bug occurs when you have many projects in a work space and some of them is configured wrong(red exclamation mark appears). Fixing project build path and other settings(even if this project is not related to the one you have problems with) should fix an issue.
For me, the reason that this error started showing up was due to classpath getting over the limit on windows. Then I discovered the option "Use temporary JAR to specify classpath (to avoid classpath length limitations)". Selecting this option fixed the problem for me. The option resides in Run/Debug Configuration, Classpath tab, see the image below.
My Main class could not be found or loaded problem is caused by an interesting reason.
In our project, we are using Maven as build tool and my main class extends a class, which is on the class path but its scope was test, while the main class is not under the test package.
If your main class extends a class, first try to run your main class by removing extends part. If it runs, you will at least understand that the problem is not because of run configuration or eclipse but the class, your main class extends.
this could cause of jdk libraries if you had imported into jre
this happen to me , so check installed jre jars
in eclipse click on Windows > Preferences > Java > Installed Jres > click on Jre and edit after that look into jar list make sure none is of jdk or corrupted ,
I had the same problem with correct .classpath file, and soon found actually it's not the .classpath file counted (after I fixed this issue, I replace the workable .classpath file with the original one, the project still worked, which means the .classpath file was not the case)
Since it's a Maven project, all I did is:
mvn eclipse:clean
delete eclipse project
import the project
done
This problem is also caused when you have special characters in your workspace path. I had my workspace in my personal folder and its name was in Greek, so it didn't work. I changed my workspace, now contains only english characters in its path, and now the project is built without any problems.
If You are using eclipse then the following steps will solve your problem:
Go to Run -> Run Configurations -> Main Class Search -> Locate your class manually -> Apply -> Run
I had this error. It was because I had
static void main(String[] args)
instead of
public static void main(String[] args)
I spent nearly an hour trying to figure that out.
Note: The only difference is that I didn't declare main to be public
To solve this error do the following steps:
Step 1: Open the .project file.
Step 2: Check two tags...
a) <buildSpec>
b) <natures>
Step 3: If the above-mentioned tags do not include any content then surely the above error is going to occur.
Step 4: Add the following content to each tag in order to resolve the above error.
For <buildSpec> :
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
For <natures> :
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Step 5: Save your file by hitting ctrl + s.
Step 6: For safe side just close the project once and reopen it.
Step 7: That's it. You are ready to rock!!!
Please mention in comments if the solution was helpful.
Thank you.
I run into the same problem, but in my case it was caused by missing (empty) source folder (it exists in original project, but not in GIT repository because it's empty).
After creating the missing folder everything works.
I ran into this error today because I set up a hello world program and then cut and pasted a new program into the same file. To fix the problem of not finding hello world as the last was called I clicked Run-> Run Configurations and then under Main Class I clicked search and it found my new class name and replaced it with the correct new name in the text that I pasted. This is a newbie problem I know but it is also easy to fix. I hope this helps someone!
Douglas
Mostly this happens, because Eclipse cleans the .class files, but don't build them again. Check the bin folder, it should be empty. Then you should check, is there anything else, which is causing build ti fail. You might have added some jars in classpath, which Eclipse might not be able to find.
Just go to your Package Explorer and press F5, or for some laptops fn+F5. The reason is that eclipse thinks that the files are somewhere, but the files are actually somewhere else. By refreshing it, you put them both on the same page. Don't worry, you won't lose anything, but if you want to be extra careful, just back up the files from your java projects folder to somewhere safe.
These are the simple steps, which helped me to solve this problem.
Close the eclipse
Delete ".metadata" folder in your work-space. (may be hidden folder)
Open the eclipse (it will automatically create ".metadata" folder in your work- space)
Try to run the program.
Check the workspace error log (Windows-> Show View -> Error log). If you see any of the jar's imported is corrupted, remove the corresponding repository folder and re-import again.
2 types of solutions exits for the same.
(1) Go to run configurations: - run->run configurations
In the Classpath tab:
Select Advanced
Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
(2) If first solution is not working then it means the jar you are pointing out to your project is taking the path of your local Maven repo which is not getting updated to your project so better you check the jar from that local maven repo and copy it paste it into new project simply or just download it from any site and configure it into your build path.
I hope it helps.
This problem occurred for me when I deleted a ".jar" file from Eclipse project by right clicking on it and hitting "delete" (not from "Build path").
To solve, I tried the following steps:
1- Right click on the project
2- Build Path --> Configure Build Path
3- Libraries
4- Delete the jar file from there (I see a red mark beside it).
I received this error as well, just after moving some resources. Checking the error log, I saw that Eclipse couldn't make a build since it couldn't remove a file/folder. Try manually removing the "bin" (or whatever it's called for you) folder.
Can be resolved by updating your project.
For example if you use maven and eclipse as you mentioned, do those steps:
Right click on your project
Click on Maven
Click on Update Project...
Click Ok
I just had this problem after first having the problem of Windows 8 refusing to update my path no matter what I set JAVA_HOME to - java -version reported the last JDK instead of the one I stored in JAVA_HOME. I finally got that to work by putting '%JAVA_HOME%/bin;' at the front of the path environment variable instead of at the end. Then I launched Eclipse and all the sudden it could not find my main class when it worked fine before this. What I did to fix it was went into the project properties, removed the existing JRE library from the libraries tab, added a new JRE by selecting the "Add Library" button and then followed the prompts to install JRE 7 as my default JRE. Now all is back to working.

Maven 2 project error icon in Eclipse

I have create multi-module maven project in Eclipse IDE (already installed M2Eclipse plugin). There I can build my project successfully. But after build also it shows errors icon in my every module project. What kind of issue it can be?
Thank You.
Without knowing what errors you are seeing I am going to assume that your issue is with eclipse project properties (build path, src directory specification, output classes directory, etc).
You tagged m2eclipse plugin, so you should be able to right click on your project in eclipse select maven->update project configuration. If you do not see that option under maven then you should first see an option called maven->enable dependency management. Click that first and then you should be able to see update project configuration option.
If this does not fix it, then open your project directory containing the pom.xml file in command prompt and run mvn eclipse:eclipse.
One of the above should resolve those pesky error messages provided that your maven build itself is successful.
In eclipse open the Markers Tab (You can open it from Window -> Show View -> searching Markers)
It will show all the related errors with your project. You can identify your problems related to your problem, and solve accordingly. Sometimes it shows Quick Fix option, which is helpful.
For me, the above solution listed out by #CoolBeans was not working out, so i searched further and found out the following:
Go to Problems windows(present besides of Console window). If it is not there then click on Window-> Show View -> Problems
Inside Problems you will be able to see the Errors Description related to your project. In my case it was "java compiler level does not match the version of the installed java project facet". If that is the case for you as well, just follow below steps:
Right Click Project -> Properties
Click Project Facets(present in the left hand side list)
Choose the correct java version in Java Project Facet
Click Apply
That's it!

Eclipse Problems View not showing Errors anymore

For some reason Eclipse is no longer showing me Java compilation Errors in the Problems View.
It is still showing Warnings.
This has suddenly happened and I cannot think of anything that I have changed which would affect this.
I am using the "Maven Integration for Eclipse" plugin but I have been for some time - not sure if this could have affected it or not.
Any ideas?
I had same problem and randomly did such things as (several times):
1) Project->Clean...,
2) close and open Eclipse again,
3) Run As...
And it started to work again, without changing configuration.
Right-click your project and go to Properties > Java Build Path > Source.
Make sure your source directory (for example MyProject/src) is listed as a Source folder. Otherwise you won't get any red markers.
I want to post my story here if Google brings you to this question.
Somehow, "Project->Build Automatically" got turned off.
Turning it back on produces correct errors list.
In my case it has nothing to do with m2e 1.0. This is default behavior for any Java project and goes back as far as Ganymede ( at the point of writing this post I am running Indigo )
This is not totally an answer to your question, but is related. I thought eclipse stopped showing red/yellow flags next to files in my project. The solution was very simple - I was looking at the Navigator tab (which doesn't show error/warning flags) instead of the Package Explorer tab.
I installed and deinstalled ajdt-plugin and got the same problem.
Check <Project><Properties><Builders>.
It should have a 'Java Builder'.
This code should be in the .project file (file is in the root of your project):
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Check your source directory is listed in source folder of project
Right-click your project > Build Path > Configure Build Path > Source.
If you are using multiple projects (as dependencies)
Project->Clean...,
Check "Build Automatically" is enabled or not.
project > Build Automatically
What worked for me is creating a New Problems View (this option is accessible from the three-dots View options):
The new View does show all the warnings and errors that were detected:
I was experiencing this problem as well today. The other solutions presented here (such as cleaning the project and restarting Eclipse) did not work or were not applicable to my setup. What did work for me was right-clicking on the project in the Package Explorer and selecting Maven->Update Project Configuration. Evidently some source folder restructuring I had done the previous day had caused Maven to lose track of things, and issuing this command fixed everything.
At the top right corner of the problems window (next to minimize) there is a small arrow-icon. Click it and select "Configure filters". There is a severity filter that might have been activated.
I have the same problem in slight different situation. I have a parent POM and multiple modules under it. Project was existing and I imported it into eclipse. I can change the "Dependency management" only to parent project but not projects under it. They are not showing any compilation warnings.
Next I'm going to try to change them all into individual projects... that's not what I wanted, but I haven't been able to solve this otherwise...
I have also faced the same problem.
After installing m2eclipse plugin, i was not getting any Java compilation errors.
My solution was to enable dependency management by Select Project -> Right Click (to get context menu) -> m2 Maven -> Enable dependency management.
Now i am able to view Java Compilation Errors.
This is normal problem. In wich order and export function sometimes get turned off.
right click on project<properties< there u hav option
build path < and there ORDER AND EXPORT< click right all the options....all the things are right back.
On Ganymede, check the configuration of the Problem view:
('Configure content') It can be set on 'any element in the same project' and you might currently select an element from the project.
Or it might be set on a working set, and this working set has been modified
Make sure that 'Match any configuration' is selected.
In my case Eclipse wasn't properly picking up a Java project that a current project was dependent on.
You can go to Project > BuildPath > Configure BuildPath and then delete and re-add the project.
There are obviously several reasons why this might occur, and I thought I'd add the solution to my issue. (I have a java project into which I have imported files with virtual links)
If you have a situation like mine, you will have another folder on the same level as your 'src' folder. If you do, right-click on that other folder, then select 'Build Path' > 'Add to Build Path' (if you see 'Build Path' > 'Remove from Build Path', then it had already been added.)
To further configure the Build Path, right click on your top level project dir, and select 'Build Path' > 'Configure Build Path'. Your folders should show up in the 'Source' tab.
To configure what errors you see, Click on Java Compiler > Errors/Warnings and then click 'Configure Workspace Settings'. That is the same as going to Window > Preferences > Java > Compiler > Errors/Warnings. If you don't want Eclipse to ignore something, then just change it to Warning.
Try following:
Open Problems window (Windows -> Show View -> Problems)
Right click on the error and then Quick Fix
This procedure helped me solve the same problem.
If you have reached here that means all the other solutions did not work for you.
One reason could be your source folder is not a java project.
Solution would be to run below command on the source folder
mvn eclipse:eclipse
This worked for me.
If this also doesn't work then try removing .classpath and .project file and run the above command again
I could reproduce this issue by creating an enumeration with a non-static member class and a static block enumerating its values:
public enum Foo {
Dummy(new Bar [] {new Bar()});
static {
for (Foo foo: Foo.values());
}
private Foo(Bar [] params) {}
public class Bar {}
}
This class breaks the Ganymede compiler. If you delete the line in the static initializer block, the code compiles correctly again, and you get the error that there is no enclosing instance for the new Bar() call, as expected.
-- correction: The above holds only if the project has gaeNature from Google Appengine. However, if you get an error similar as mentioned in the original question, you might be encountering another java compiler bug ...
I have the same issue with Eclipse Helios and the m2eclipse plugin. They just can't seem to get this thing to work with WTP or WPT or whatever the blasted acronym is.
If I do a clean on the project and watch the Maven console then I can see the compilation issues in the console but eclipse won't touch it. It seems eclipse or WTP/WPT and m2eclipse are busy playing slap hands.
I experienced that problem with a MapReduce project. I closed the error window and never came back after doing what the other answers suggested.
Click on the bottom left -> Other -> Problems
Kepler SP2, Java Project (Web Driver), and we use Gradle instead of Maven
None of the above helped, what did fix the problem for me was to select my projects (r-Click) > Gradle > Refresh All
Pointing the source(src) folder to the build path will solve this easily
to do so
right click on the project > build path > configure build path > java build path > source > add folder and click Apply
My mistake was that I was creating classes in resource package...
Creating classes in src/main/java solved the issue.
Check your filters, sometimes problem view could be scoped to a working set that you are not currently working in. Also, you can check other configurations for the problem view.
Problem in .classpath
I did "Replace with HEAD revision" to get back the version that I had in the repository Git and the errors appear again.
Duplicates in build path
In my case, errors were not showing up in the Problems View or Package Explorer views because my build path had duplicate entries for src and test directories:
Removing these from Project -> Properties -> Build Path (and just leaving one each) did the trick.
In my case I setted a old workspace and it was the problem.
Try to set a new folder for workspace
If "Debug" has been recently activated then check the top right of the program (under the Minimise button) and click back onto Java.

Categories