Missing .classpath file in Eclipse project - java

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.

Related

My laptop has saved all files to a class path. How do i remove it?

I'm using eclipse and I had saved a file. however, all the projects have a classpath now. I don't know how this happened. Is there any way to remove it. this is how my files have all changed now:
That belongs to the eclipse project configuration of a java project (like the .project) and you should not remove it.
BUT you can hide it from your view:

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.

Some projects cannot be imported because they already exist in the workspace [duplicate]

I am trying to import a project that me and my co-worker have been working on.. and keep getting this error after I select-- "import" then "import existing project" then click archive file, and then I click next, and this error comes up:
Some projects cannot be imported because they already exist in the
workspace
Uncheck the "copy projects into workspace" checkbox, and then click "refresh" button, you will be able to import the project
go to .project file in your project and change the name of the project in name tag
It has just happened to me too. Finally I realized that the project was already open in my workspace but it was not visible because of the selected working set. You have just to deselect the active working set and all opened projects will become visible.
This usually happens when you change the project directory physically without first delete in Eclipse.
You can view and delete these hidden projects in the following view:
Window -> Show View -> Other -> General -> Navigator
Then simply just continue with the process of import existing project.
In my case, I copied one of the projects (say 'Project1') from the workspace and pasted it to the same workspace. After that I modified the name of the pasted project (say to 'Project2'). I could not see it in the repository.
The main reason was .project file from the new project still had:
<name>Project1</name> instead of <name>Project2</name>.
So, I did following things in order to get the issue fixed:
Cut and paste Project2 outside the workspace
Change .project file to have <name>Project2</name>
Try importing Project2 again.
It worked for me.
You may have a project with same name in your workspace. Try to refresh (file->refresh) your workspace after deleting the another one with same name.
A typical situation occurs when you want to re-import a deleted project.
Projects in the Eclipse workspace must be unique. Note though that the project name need not be the same as the directory/folder name of the project, so you can either delete any existing project with the same name or alternatively rename the existing projects.
You have one occult directory named ".metadata" in workspace directory. Close Eclipse, delete ".metadata" and open Eclipse. When eclipse ask you about workspace make sure that ".metadata" isn't in workspace directory and click "ok" button to select default workspace.
Maybe you get the same project name in your '.project' file,check it,if yes, rename another name.than import again
If you've arrived at this because you have cloned a git project into the existing workspace and now you want to promote that workspace to a full fledged project then you should use the 'Git Repositories' view -> select 'Working Directory' -> Import Projects -> Existing projects.
Check if you have configured Eclipse to show ALL the working set. I once encountered exactly the same problem and it turned out I accidentally imported the project into the Other Projects working set. And my Eclipse configuration didn't show that working set in the package explorer, which lead me to believe that the project was not imported yet.
Updated for #Mawg:
First, click the Select Working Set...:
Then, choose No Working Sets:
This will effectively disable the working set and show all projects.
Try to rename the value of <name> tag which inside ".project" file of your project.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Rename this value</name>
<comment></comment>
<projects>
This will work for sure. Here you are just renaming your project.
EASIEST WAY: Right click on the project (folder that reads "MainActivity") go to Refactor -> Rename and you will get a text field allowing you to rename your project.
If you get an alert saying your project is out of sync with the filesystem press F5 (refresh) and try again.
Take a look in your workspace folder, you may have an old project there with the same name as the one you are importing (even though it's not being shown on eclipse).
When you delete a project on Eclipse, if you don't check the checkbox on the dialog, it just removes it from the view and doesn't delete the folder on the workspace directory.
In my case i had deleted the resources directory from my .metadata.plugins:
Go to your workspace
Enter .metadata.plugins
Delete : org.eclipse.core.resources directory
Another way I just found!
MOVE the project to some other folder and then import and if required copy to workspace
I had this issue when I deleted a project and tried to import the code again. Eclipse never really deleted the project and still held a reference to the project name/folder in the workspace. I had to created a new project with the same name and my code appeared as it was. I believe this only worked because the project path was never changed.
It was happened to me when
I delete project from eclipse Project Explorer and not checked the
remove content from disk.
Next time when I tried to import same project in workspace then got same problem.
To solve I just did FYI work that every kid can do :)
So How I solved it:
Cut Ctrl + x myProject folder from eclipse workspace to other location ie Desktop
Right Click Navigator (you can get it from Window > Show View > Navigator) and Refresh (it will prompt following dialog)
Just click Yes button and move your project folder back to eclipse workspace directory
Import again!
Now Rock 'n' Role
This warning means you just deleted project from navigator, but the project is present in the working set. Or else your working set has project with same name, so go to work-space directory and delete the project which has the same name and import again.
This worked for me.
File > New > Android Project > Create project from existing source
Location = the location of the project you want to import.
You will get a warning "An Eclipse project already exists in this directory.
Consider using File > Import > Existing Project instead." But you will be able to click "Next" and the project should in effect be imported.
In eclipse click file then select switch workspace then browse and select another folder. Now repeat the same process and this time there will be no error :)
I had a similar problem, I have the same repository I wanted to import twice. I renamed the existing project by right clicking on the project > refactor > rename then imported it again.
My problem was a little bit different.
For example, the project name (what I see) was FooProject and in the imported project, I was looking for the FooProject but I could not. However, Eclipse does not let me import that project because he claims that it is already imported. And then, I have looked at the .project file of the project and I have seen that the actual name of the project was not what I see (FooProject).
The conclusion;
The name of the project (what you see in Eclipse) may be different than the actual name of the project (what maven see). Because of this reason. Please be sure that they are the same name by checking .project file of the project.
Nothing about could not solve my situation. This is how I solved.
Close the IDE
Remove the same name project form workspace
Start the IDE
Clean all project (not sure this helped)
File > Import > Existing Project
click refresh button
import project
Done..
At least on Eclipse Juno, you can toggle on Advanced. Then select [groupid].[artifactid] from the Name Template dropdown. That should make your project uniquely named. (If you keep multiple versions of a given artifact, you can select [groupid].[artifactid].[version] instead). Be sure to click the Refresh button so the changes are visible. Wash, rinse, repeat as needed.
delete it from eclipse......u might have closed the project in eclipse by "(Rightclick)-->close project".....so even if you delete this project from workspace folder....it stays there in eclipse IDE as closed project.....you should delete it from Eclipse IDE...!!!
I have a slightly different situation whereby my eclipse stops responding and I have had to kill the session. After restarting Juno, then the particular project I was working on disappeared although .project file exists. Trying to import back into Eclipse would yield the same "Some projects cannot be imported .." or "A project with this name already exists" if trying to create a new project.
In the end, since I was using Working Sets, I managed to find this file .metadata.plugins\org.eclipse.ui.workbench\workingsets.xml. Manually added the missing entry and restarted eclipse and voila, it came back.
I had the same error because there was one more project under svn in workspace but with another name. So I've removed it.
This is what i have noticed for the above issue :- If the checkout folder (folder where your pom project resides) is same as the eclipse workspace folder then i am getting this issue
SOLUTION
when i used a separate workspace folder for importing the project, eclipse did worked smoothly :)
In case you are using Maven, make sure that your artifactId in pom.xml does not have the same name as any existing project name in your Eclipse project explorer.

.project file missing in Eclipse but can be seen in Win Explorer

I am using Eclipse Luna. I working on a couple of projects before the weekend. Win 7 did a magical reboot/install and this morning none of my class files are being shown in the Package Explorer within Eclipse. I have checked the path to my files locally via GIT and they are all there including the POM and .project files. but Explorere is complaining that the resources do not exist. I have tried opening the project and I get:
The project description file (.project) for 'brightside' is missing.
This file contains important information about the project. The
project will not function properly until this file is restored.
But the .project file in my GIT path. To also add the folders color in the Package Explorer are now Blue.
Any advice to get me back to a productive status would be appreciated.
Thanks,
Eclipse's view of the file system may be inconsistent after the forced exit.
First thing to do when a workspace was not cleanly closed: select the project(s) in question and refresh (F5).
If that doesn't help the next level would be: launch Eclipse with -clean command line option.
Additionally the Package Explorer may be hiding .* files, check Filters ... in the Package Explorer's view menu.

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.

Categories