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.
Related
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.
For every version of Eclipse I've used prior to Juno, ctrl+click would find the declaration of a variable/class/method. It was an extremely useful feature when dealing with a large code base. How do I get Juno to do this?
I can confirm that Ctrl + click works fine with the following :
Eclipse Java EE IDE for Web Developers.
Version: Juno Release
Build id: 20120606-2254
Operating System : Windows 7, 64 Bit
What do you have for the following preference ?
On Window -> Preferences -> General -> Editors -> Text Editors -> Hyperlinking -> Open Declaration
Here is what I had for a new workspace in Juno :
Update
I have not experienced this in the recent past, but I vaguely remember encountering this problem in previous Eclipse releases (Galileo and earlier).
All of what follows is worth doing only if we are sure that it's a problem with the Eclipse workspace. A quick way of checking this is to restart eclipse with a new workspace (Do this by going to File -> Switch Workspace -> Other... and choosing the path to a folder which is preferably empty and different than the current workspace folder).
If things worked in the new workspace, my fix then was one of the following, in increasing order extremeness :
Re-start eclipse (Yup, sometimes that is all it took)
Re-start eclipse with the -clean parameter to clean out the workspace ( See this). This might specially be worth doing if you used a workspace from an older version of eclipse.
When the above failed, and I just had to use my existing workspace, I backed up my workspace folder and restarted Eclipse after deleting WORKSPACE_FOLDER/.metadata/.plugins/org.eclipse.jdt.core
For me it helped to simply close the edited source file and reopen it.
If this doesn't work THEN you can try restarting whole IDE.
For my situation I solved this problem by going to the project properties, select "Java Build Path", and then removing source folders that does not exist anymore.
This bug is really annoying..
The only thing that did the trick for me is deleting the project from the workspace,
then deleting the .project and .classpath files and then re import it back to the workspace.
Hope it will help others.
I had the same issue with PDT in eclipse, I fixed it by removing my include build paths and adding them again.
The solution for me was to configure the build path to include the project itself.
Right click on open project.
highlight build path
click on Configure build path…
click on Source
Click Add Folder… button.
Put a check mark next to your project.
Click OK.
If necessary, click the project menu and choose the ‘clean…’ option to rebuild.
I found resolving issues with the project's Java Build Path settings fixed this issue.
Right-click the project, select Properties, select Java Build Path.
(NB: I'm using Eclipse Kepler Service Release 2 on Windows 7)
If you're working on a large project and are working with a repository, you could just have the file opened via the wrong project, I just had two instances of the file open, where one was the one where I couldn't do Ctrl + click, while on the other file I could Ctrl + click on it successfully.
I was facing the same issue in eclipse. I verified preferences and build path and also no error. Tried closing and opening the eclipse but nothing worked. Even I could not run debug configuration. I created a new workspace and Ctrl+click / ⌘+click (Mac os) was working fine.
Hope this may help someone.
I had the same issue, and solved it the following way.
My issue came because
I imported a project from Git, which wasn't having the project file. So Eclipse was not recognizing the project as a java one. Ctrl+click was not working and so there was the F3 issue.
Solution:(not a direct one. but solved my issue)
import -> projects from git -> from URI -> select the new project
wizard
so an empty project with src folder will be created.
then copy all the src files in to the folder manually.
Sometimes if a file is too large, then for Scalability purposes, the navigation is disabled by Eclipse. For me it happened with Eclipse with C++
It can be enabled by Window->Preferences->C/C++/Editor/Scalability and then under "Scalability mode settings' uncheck everything.
Go to
Window -> Preferences -> General -> Editors -> Text Editors -> Hyperlinking
and be sure that
Enable on demand hyperlink style navigation
is checked.
I faced this issue several times. As described by Ashutosh Jindal, if the Hyperlinking is already enabled and still the ctrl+click doesn't work then you need to:
Navigate to Java -> Editor -> Mark Occurrences in Preferences
Uncheck "Mark occurrences of the selected element in the current file" if its already checked.
Now, check on the above mentioned option and then check on all the items under it. Click Apply.
This should now enabled the ctrl+click functionality.
I encounter this problem when creating workspace/project in eclipse 3.7.2. Then I open it using Kepler (4.3).
So simply open the project by the eclipse version you created it (3.7.2 in my case) solves the problem.
Hope it helps.
I had same problem; i tried to Change in preference, clean work space etc. nothing worked.
Solution:
Finally i found there is error in class path configuration; after fixing this everything became normal.
On my system, Ctrl+click brings up the right-click menu instead of opening the declaration. However, if you hold Ctrl and hover the mouse pointer over the variable/class/method name, a small boxed menu appears with "open declaration" at the top. You can move the pointer down and click that item to get the desired effect.
I'm running Ubuntu 14.04 through VMWare on OS X.
I'm having the same issue in Eclipse Luna in my Ubuntu VM, but I just tried to Ctrl+click on a method and it worked (even though my mouse cursor didn't change to a pointer).
You need to rebuild your workspace using CTRL+B.
I a problem where I'd be able to go to the function declarations but for some I wouldn't.
After a rebuild, I could do all.
I hope that helps.
Please check your .classpath file as well. Some times Eclipse do not redirect when using "ctrl+click" to Class or method if classpath is not proper. I had faced same issue in Eclipse Mars but it got resolved when I got proper .classpath file at my work location.
If the project is a Maven project, make sure that the java class you have open is inside src/main/java.
I had the exact same issue while working on a GIT based project. I was able to resolve by changing the way i was importing the project in the workspace.
Wrong way : Import project to workspace from GIT perspective , like right click on the GIT URL and selecting the option import which was not recognizing the project facets.
Right way (which resolved my issue): clone the project in GIT perspective , change to JEE Perspective , then import from file > import > Existing Maven Project .
I had similar issue, along with this I found that java build path in project properties was missing.
Project pulled from repository did not had .project file and eclipse created a default .project file, I copied content of .project.xml from other working project and removed the unsed imports, After which everything worked fine
<projectDescription>
<name>XYZ</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
If your build path is correct, the ctrl + click will work
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.
I have recently returned to a project after not using it for a couple of weeks. The project was not created in Eclipse it was imported, and there is no '.classpath' file in the project workspace.
I am sure that previously I successfully added new .jar files by simply right clicking them and going to 'Add to build path', but thanks to an unrelated error I had to re-add the files to the build path, and now whenever I try to add a new .jar file I get the following error:
Error while adding a library
Reason:
Could not write file C:\Users\Charles\workspace\hive\.classpath
Or, if I try to add a file using Configure build path, I get the following error:
'Setting build path' has encountered a problem.
Could not write file:
C:\Users\Charles\workspace\hive\.classpath
I have earlier versions of this project prior to adding .jar files, and there is no .classpath file for any of them either, so I haven't accidentally deleted it at any point.
If anyone can help me out at all, I'd be ever so grateful (I desperately need to add these .jar files so I can do some actual work).
The thing that annoys me the most is I'm sure it worked before, but I have tried to do the same in earlier versions of the project and I am always getting the same error now.
I had the same problem. I had just setup a new PC, I transferred my projects to the new PC, clicked on the workspace directory, and changed the permission so that I (the 'me' on my new PC) owned all the files in all all sub-directories. However, even after doing this, eclipse couldn't write to the .classpath files. I verified that I could write to them using notepad, and that worked fine. I also verified that the O/S knew I was really the owner, but it didn't help. I also tried running as admin, but that didn't help either.
Then I found this link: http://blog.ryanrampersad.com/2010/03/03/setting-build-path-has-encountered-a-problem-in-eclipse/, which indicates that when you copy files to a windows7 machine, windows may set the 'hidden' attribute on the file, and when this happens, eclipse can't work with it. I did a find files from the workspace directory, looking for '.project' (and subsequently '.classpath'), and selected all the files, right-clicked, and un-checked the 'hidden' attribute. This fixed my problem.
The .classpath file in eclipse is a configuration file (in XML) which stores the project classpath properties. If it can't be written, perhaps it's an access problem. Right-click the file in windows explorer and check under the security tab to see if you have write permissions. You may have to run Eclipse as administrator.
Go to your Project in WorkSpace.
And then change your files' attribute from hidden.
Also, then close-open your project and then clean it.
This should work.
Right click Project >> Source >> Format - worked for me!
Go to the project folder and remove hidden property for the ".classpath" file. Hope this helps. Thanks.
The below solution worked for me.
Go to your project folder --> Right click folder --> Properties --> In general tab, Uncheck the attribute(last field), Read-only (Only applies to this folder) option.
Then try adding jars in eclipse.
Hope this helps
As doc_180 mentioned, the .Classpath would be hidden. Right click > Properties and Unhide the file, you should be ok.
Just had the same issue after trying to create my view on a new PC. The cause of the issue for me was that .classpath file was marked as read-only, for whatever reason. To resolve this I did the following:
Go to workspace directory --> Java Source folder --> Project Directory --> right click on .classpath and select Properties from the list --> uncheck 'Read-only' and/or 'Hidden' attribute checkbox(es) --> Click 'Apply' button.
I had a similar problem after changing my project to Gradle. When I right-clicked on javaw.exe->Properties in the 'debug' view, I saw the classpath was (mostly) missing, for instance the 'bin' directory containing the classes wasn't there.
Solution for me was just to delete the 'run debug configuration' and create a new one. After that the classpath was included and I could run it from Eclipse again.
Hope this helps someone out there.
An intern here just had this problem. He put the project on the user Document folder. I moved his project to the Eclipse workspace folder, removed the project from Eclipse and imported it again. Then the .classpath file was generated.
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.