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=""/>
<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>
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.
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.
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.
i was running through the similar problems in my small java snippet
here is what i did.
i copied all the content in the main class.
deleted the main class greeter.
right click -> created a new java class with name greeter
a> checked include main method when creating class
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.
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!
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
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.
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:
- 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!
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.
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.
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.
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
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.
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
- click on
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
i had the same problem. spent few hours and finally changed my workspace back to local folder and everything works now.
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 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.
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.
i faced the same error, the error was in one of the imported external jars. after removing that jar project worked for me.
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.
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.
follow the steps it works for me:
- remove configure build path from eclipse(build path)
- add configure build path->source->add folder->check src ok.
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.
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.
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:
select only the jar files wherever you want and don't be too lazy to add text and other types of files. or,
select all files within a specific folder where you wanna add jars from, and then remove one by one, which are non-jar files.
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:
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.
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!
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/
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.
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.
in your eclipse preferences -> java -> installed jres -> select the java se the jdk which you have on your machine and add the jdk
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..
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 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.
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.
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
4- delete the jar file from there (i see a red mark beside it).
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.
i had this error. it was because i had
static void main(string args)
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
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
to solve this error do the following steps:
step 1: open the .project file.
step 2: check two tags...
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.
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.
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
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
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
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.
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"?>
well the following worked for me...
- went into the project folder (inside
- then, deleted the
- 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.
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:
the problem was that i made my maven project available to github. it moved my project to my github folder.
- 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.
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 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 )
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
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.
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.
- Error When Compiling on Eclipse Luna with JavaCC - Could not find or load main class javacc
- Error Could not find or load main class springboot eclipse
- Eclipse Error: Could not find or load main class
- Scala Error: Could not find or load main class in both Scala IDE and Eclipse
- Error: Could not find or load main class in Eclipse
- Could not find or load main class weblogic.server in eclipse
- Eclipse -> Error: Could not find or load main class hello
- eclipse error: could not find or load main class for project
- Could not find or load main class org.testng.remote.RemoteTestNG - in Eclipse
- Java Eclipse Maven Could not find or load main class with jdk
- Error: Could not find or load main class ... - Maven project out of Eclipse
- Error: Could not find or load main class with Spark in Eclipse
- Eclipse won't compile into bin , Could not find or load main class
- java eclipse patched JRE classes Xbootclasspath Could not find or load main class
- Eclipse - Error: Could not find or load main class
- Could not find or load main class Eclipse
- Eclipse IBM Webshpere startup Could not find or load main class VS
- Error running cucumber in eclipse- Could not find or load main class cucumber.api.cli.Main
- Eclipse on OS X El Capitan Error: Could not find or load main class
- Eclipse Error: Could not find or load main class opencv
- Eclipse debugging stopped working: Could not find or load main class
- Error: Could not find or load main class in eclipse IDE after cleaning project
- After converting to maven getting error : Could not find or load main class
- Trying to run a java program in console will give a could not find or load main class error
- Eclipse Error: Could not find or load main class
- Error: Could not find or load main class Mac Eclipse
- error could not find or load main class -eclipse?
- Gradle build error in eclipse: Could not find or load main class Files\OpenJdk11\lib\security\cacerts
- Eclipse IDE Error: Could not find or load main class javafx.fxml Caused by: java.lang.ClassNotFoundException: javafx.fxml
- Getting "Error: Could not find or load main class aQute.launcher.Launcher" in Eclipse IDE even though it works in command line
More Query from same tag
- How do you switch your library projects in eclipse
- How to update java on macOS Sierra 10.12
- Eclipse Installing Android app on Device Stopped working
- How to run google test-analytics project on appEngine using eclipse
- Eclipse and EGit: how to commit build directories
- JRebel not working on external tomcat 7
- Most robust way to convert a CVS repository containing Eclipse projects to git?
- hiding tab in pde
- Error: Failed to find provider info for com.google.settings
- Search for all files in project containing the text 'querystring' in Eclipse
- How to generate getter and setter in eclipse (php)
- How to get a warning if some code is blocking the main thread in SWT?
- Eclipse drools plugin cannot edit constraints
- Unable to generate class model after modifying my *-items.xml file
- Eclipse Error on Startup: Error notifying a preference change listener
- Eclipse: copy the selected snippet automatically
- Deploying war into OSGI at Runtime
- Tomcat 5.5 Deployment - Not Picking Up Class
- My android virtual device is not showing contents
- Robot class- KeyEvent fails to upload document to the windows folder at KeyEvent.VK_V
- Integrating multiple GWT applications into a pluggable platform
- Trying to merge two JSONobjects in android
- Xtext, get Iselection Input in the LaunchMydslShortcut
- How to import the hundreds of API Demos in the android SDK when so many are called MainActivity?
- problem running eclipse on ubuntu?
- Permission denied while connecting to the repository using subeclipse
- Updating Swing DefaultComboBoxModel
- using Toshiba AT300 as Device in Eclipse
- JSP cannot be resolved to a type
- Download Legacy JVM Version 1.8 for MAC High Sierra