score:45

Accepted answer

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"/>

score:0

try also renaming the package before changing the configuration or reinstalling.
i got this weird error without having changed anything else than a few lines of code. rebuilding did not work, eclipse would not re-create the class even though the bin folder was empty. after renaming the package from test to test1 eclipse started rebuilding and everything was fine.

score:0

what i ended up doing is in eclipse, copy the entire project and paste it again (and give it a different name of course). then run your copied project. it should ask if you want it to run as a java applet or as a java application. click on java application and it should work again. then you can remove the original project and rename your current project to its original name if you wish.

score:0

i had a very strange reason for this error. some of the files referenced in the local maven repository (~/.m2/...) were corrupt. after deleting these and then rebuilding the application, it worked. using a newer version of maven exposed the corrupt files.

score:0

i was running through the similar problems in my small java snippet

here is what i did.

  1. i copied all the content in the main class.

  2. deleted the main class greeter.

  3. right click -> created a new java class with name greeter

    a> checked include main method when creating class

  4. voila !!! i was able to run as java application by right clicking on the main class greeter.java.

just out of curiosity i again tried deleting the greeter class and creating new class without checking main method, and it did not show me run as java application option in right click.

score:0

i too faced this issue today. whatever new class i created with main method i faced the same issue. then i checked the build path and saw that one of the java api jar file - nashorn was showing as missing. i put it back in the ext folder and it worked!

score:0

sometimes, it might have a very simple solution

you have perhaps added a new version of the existing .jar file and forgot to remove the old version of the same .jar file.

now try removing the old jar files (that are marked in red) in the build path > configure build path

score:0

a very simple fix coul’d be delete a commented error in the pom.xml.

i don’t now why, but the error coul’d persist in the pom, even if you comment it. in my case, it was an innecesary scope tag for mockit or whole dependency of mockit, all commented!!! it was sufficent delete the commented lines and save the pom.

score:0

the same error i am facing in my eclipse and going through above all did not help me out, so here are the steps you can do:

  1. check the problems- windows->show view->others->problem if you find something their errors saying "a cycle was detected in the build path of project xxx - build path problem". then do simple thing: mark circular dependency as a warning: windows -> preferences -> java-> compiler -> building -> circular dependencies and it will fix your problem. never forget to clean the project after that: project->clean

hope this will help!

score:0

if your project is a maven project, make sure there are no missing dependencies from your project's pom.xml.

in eclipse, the opening '' should be highlighted in red if is not found in the repo - delete all these dependencies (or fix them).

once all the missing dependencies are removed, you should be able to run the class.

score:0

i resolved this by just deleting the project in eclipse / spring tools suite (without deleting the sources!). then going into the directory where my project was and removing the .settings directory and anything related to eclipse, i then re-imported the gradle project and the problem was resolved.

this happened after i moved the entrypoint file to the spring boot application.

score:0

i hadn't worked on my gradle project for a while and i got this error. i right-clicked on the project -> gradle -> refresh gradle project. that worked for me.

score:0

for me, i faced same problem after importing the maven project from git. it got solved after using new jre in build path by using below steps in eclipse.

eclipse project properties->java build path->libraries->jre->edit->execution environment->javase-17->finish and then rebuild using run->maven install. this time no error was seen

score:0

the following worked for me after migrating an eclipse project from one computer to another and when right click myproject->refresh did not do the trick.

project explorer->myproject->build path->configure build path->java compiler: check enable project specific settings and select apply.

this rebuilds all the class files in the myproject/build directories.

score:0

can be resolved by updating your project.

for example if you use maven and eclipse as you mentioned, do those steps:

  1. right click on your project
  2. click on maven
  3. click on update project...
  4. click ok

score:0

in my case none of the 30+ answers helped. i have a modular java project. the commandline eclipse offered worked, but not running the project within eclipse. what worked for me:

edit run configurations -> tab 'dependencies' -> add modules: all-module-path

score:1

i had the same problem. spent few hours and finally changed my workspace back to local folder and everything works now.

score:1

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.

score:1

i found other solution in my case this problem: eclipse->preferences->java->installed jre then press button search. select folder in linux /usr then eclipse found all jvm.

select another jvm too current. it is solved for my case.

score:1

i had the same problem after i created new package("tables") in my project.

i went to window -> show view -> general -> error log and ive read error:

javabuilder handling imagebuilderinternalexception while building: pizzaservice

org.eclipse.core.internal.resources.resourceexception: resource '/pizzaservice/bin/tables' already exists.

as it turned out i had a text file in another source folder with the same name as this new package. so i've changed text file name from "tables" to "tabless" and i could run my project again.

hope this helps.

score:1

i faced the same error, the error was in one of the imported external jars. after removing that jar project worked for me.

score:1

happened to me when i changed installed jres to jdk7 instead of jre7. everything compiled but i couldn't run anything from eclipse "eclipse-error-could-not-find-or-load-main-class"

fix; going back to previous jre7.

score:1

rename the class with ctrl+shift+r (windows), it will change name of the class everywhere where it is referred, and then do the opposite procedure. in my case it was caused by identical class names in several projects within the environment and eclipse had hard time to understand which is which.

score:1

follow the steps it works for me:

  1. remove configure build path from eclipse(build path)
  2. refresh
  3. add configure build path->source->add folder->check src ok.

score:1

i had this same problem with eclipse-mars. i had a working project then put it in my git repository. that broke the execution (i guess because the actual java files got moved to the git location and no longer existed in my workspace). i did a maven>update and it now works.

score:1

actually i found the real root cause for this issue, by going to add each .jar files manually one by one, because the following answer within the same thread, suggests you to do so.

cause:
you know as we are humans, we are really lazy creatures and that's why we have an option to "select all" and also shortcut keys to perform that. so when i have to add around 30+ jar files for a pdf generation required app, i did go in this way,

right click on project -> properties -> java build path

  • selected "libraries" tab in it, then add jars...", browsed through the directories tree and (my jars and the licence.txt files was in projects "lib" folder) within the "lib" folder, i selected all the files and added. can you guess what has been the wrong? it had successfully add all the files within the "lib" folder. but eclipse keeps trying to profess any of the text files you may have added as jar file, in this way. so it can't build the links. this is the case.

so you have two options:

  1. select only the jar files wherever you want and don't be too lazy to add text and other types of files. or,

  2. select all files within a specific folder where you wanna add jars from, and then remove one by one, which are non-jar files.

note:
if you have added any of non-jar files to the project in that way as you were trying to add "libraries", it will show you something like the following:

enter image description here

and keep trying to compile and at the end, it will give you the following error:

error: could not find or load the main class er.waterapp.some.mainfilegivenbyconfigaration

  • mainfilegivenbyconfigaration could be any class which you might have selected from configuration to be take as the starting point of the app.

score:1

i spent tenths of hours trying to solve this, and what only helped me at the end was to notice that i had in my packages some files (text files) with the same name, like todo, readme and important. i went through every package of my project renaming those files (like todo_packagename1, todo_packagename2...) and when finished, i closed eclipse and restarted it again. then worked!

score:1

i was using eclipse oxygen and the problem persists everytime. later i found that if your eclipse workspace is under the directory with non ascii characters then somehow javaw.exe couldn't reach the bin directory. suppose your directory name is work_hello the remove underscore sign and clean the project and run configurations. this worked for me. reference: https://www.eclipse.org/forums/index.php/t/1093209/

score:1

project files using a custom archive in the build path, to fix -> go into the class path file, find and remove the entry then collect a new copy of the archive and add it to the build path again. you'll need to rebuild the project and to check the "run configurations" after.

score:1

rebuilding using the command line has fixed this issue for me multiple times. for example, running ant build (for an ant project) or mvn build (for a maven project) will fix eclipse once it succeeds.

score:1

in your eclipse preferences -> java -> installed jres -> select the java se the jdk which you have on your machine and add the jdk

score:1

check if you have included any missing dependencies. in my case i've imported json jar (which is no longer present in that path). removing it from libraries helped.

libraries

to navigate to libraries (right click on project -> properties).

score:1

i faced this error today and went through all of the existing answers. however none of them worked.

my solution was: create new eclipse workspace and import the old project. this time project started just fine.

i don't know why it's fixed the issue. my guess is it happens after deleting and re-creating the project with the same name causes some problems with eclipse..

score:2

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.

score:2

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.

score:2

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

score:2

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.

score:2

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.

score:2

these are the simple steps, which helped me to solve this problem.

  1. close the eclipse
  2. delete ".metadata" folder in your work-space. (may be hidden folder)
  3. open the eclipse (it will automatically create ".metadata" folder in your work- space)
  4. try to run the program.

score:2

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).

score:2

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.

score:2

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.

score:3

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

score:3

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.

score:3

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

score:3

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.

score:4

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:

  1. mvn eclipse:clean
  2. delete eclipse project
  3. import the project
  4. done

score:4

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.

score:4

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 , enter image description here

score:5

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.

score:5

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.

enter image description here

score:8

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>

score:8

well the following worked for me...

  1. went into the project folder (inside workspace)
  2. then, deleted the bin folder
  3. then, cleaned project / projects (in eclipse)
  4. built/run from eclipse.

score:8

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:

  1. delete .classpath and .project from your project
  2. delete your project in eclipse. do not check delete project contents on disk.
  3. now, in a file explorer, go into $yourworkspace/.metadata.
  4. search for $yourprojectname
  5. delete everything you find. it should be safe-ish to delete anything in the .metadata directory.
  6. in eclipse: file > import > general > projects from folder or archive > $yourproject > finish
  7. right click your project > properties > java build path > source tab
  8. select all source folders, remove.
  9. add folder, select src (whatever your src folder is called) and add it
  10. go to libraries tab
  11. add any jars to your build path here. there should be no more errors on your project now.
  12. run your project like you normally would.

score:9

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.

score:9

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.

score:21

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.

score:34

i did all the things mentioned above, but none of them worked for me

my problem resolved as follows:

  1. right click on your project > properties > javabuildpath > libraries.
  2. remove the jar file, having a red flag on it.
  3. if problem persists try the solution below. this worked for me when i faced this problem second time:
    1. right-click project > properties > java build path > libraries
    2. remove library
    3. add library. (choose the jre system library )

score:66

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

score:83

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.


Related Query

More Query from same tag