I have a main method in a package in one of my projects. Say, the package is com.ant.car. I am trying to run and/or debug this main method, and I keep getting the error Could not find or load main class com.ant.car.
I've searched this problem, and it seems like I can't figure out what is wrong.
1) I've checked run configurations. In Run->Run Configurations, I've checked that the Main class is com.ant.car.
2) I've checked build path. If I right click on the project, I select Build->Build Path, and under the Libraries tab I make sure there are no missing folders with red Xs next to them.
Not really sure what else to do. Any suggestions?
Project -> Clean
this is working
Try updating project by right clicking on it. Maven -> Update Project
Today I ran into the same problem and I tried a lot of answers. Nothing helped. Cleaning the project, build automatically is already checked, deleting .metadata, etc.
Eventually I tried this and it worked perfectly:
menu Project -> Properties
Java Build Path, tab Libraries
Remove the JRE System Library from there, press Add Library, take the JRE System Library and press Next. Workspace default JRE and press Finish.
What worked for me:
Menu Project -> Properties
In Java Build Path, tab Libraries
Delete all libraries with a red [x] next to them.
In my case, problem happened when I switched from Kepler to STS IDE.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
Sometimes the problem can be caused by some newly added dependencies. Try removing the recently added jars. That's how I fixed my problem.
Project -> Clean... -> check project not working -> Clean
I already had build automatically set, but forcing STS to rebuild it fixed it.
This issue occurs when the main .class file moved or not found because you changed the directory for committed/shared the project into the git or another repository.
To Resolve this issue -->
Remove existing run configuration and new one.
Find the parent pom.xml or project pom.xml and open cmd/command prompt and run the below commands,
mvn clean install package
mvn eclipse eclipse
It worked for me:
1. Delete metadata from work-space directory.
2. Import the project again, but selected copy to work-space option.
I think the cause for the error was Non-English characters in the original saved directory.
You just need to delete Run Configuration file and restart STS and run command -mvn clean install and try to restart the service
The Error "Could not find or load main class com.ant.car" occur when your class is not in build path. please make sure that .class file is generated and it's in build path ..
I faced the same issue..
just do follow these steps:
STS/Eclipse --> Project --> Enable "Build Automatically"
then refresh your project, it will resolve your issue.
Still not refreshed your projects automatically, just restart your STS and check.
Hope it will help you.
I think .class files are deleted/missing from JavaProject/bin folder.
To resolve this issue ->
1) Just cut paste and save the code contents of all the files that you are using then .class files will be regenerated.
2) Then run the code and you can see it works fine if there is no syntactical errors.
1 ) Clean the Project
2 ) Enable build automatically Option
3 ) Update the maven project by use the short cut Alt + F5
Deleting target folder manually and mvn clean install worked for me
A quick and easy fix is to directly run your SpringBootApplication class (i.e. Right click, Run As -> Spring Boot App). This runs the app and creates a run configuration automatically.
I spent several hours on this issue, finally it is fixed by doing this:
Properties -> Java Compiler: uncheck the checkbox "use '--release' option"
This worked for me to solve the error. (I got this error after removing AWS ToolKit)
Close the Eclipse/ STS Eclipse.
Go to the WorkSpace folder.
Delete the .metadata folder.
Open the eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Remove project from STS/Eclipse
Close or Refresh the Eclipse/ STS Eclipse.
Run maven install on pom.
Run the project with your Run configuration.
Tried above mentioned steps to resolved issue.
You can try one of the two solutions below:
Solution 1: Right click the project -> Gradle -> Refresh Gradle Project.
Solution 2: Add gradle or maven in your environment variable. My problem was that I had not added gradle in my environment variable. Before, make sure Gradle or maven is installed in your OS.
I tried all the answers but finally what worked for me was deleting the project from eclipse workspace and importing it again.
Related
I've encountered a problem where on all of my applications, there's a red cross on the top right. I can run it, but the cross doesn't seem to go away.
I've opened the run/debug configurations and it says Warning : Main method not found. I don't understand why it's not found when I already have a corresponding main class and method for each and every application.
I tried to close the project, restarting IntelliJ, restarting my laptop, refreshing my desktop, refresh Gradle by clicking Reimport All Gradle Projects, rebuild the project and clicking Invalidate Caches / Restart. I also tried other suggestions I found on StackOverflow such as deleting the .idea folder. Nothing. The red cross still shows up. I've also realized that I do not have the out folder in all of my Applications.
I just set the language level to equal my SDK version at Project Structure. Finally, it is disappeared.
In Project Settings, First make sure SDK path is correct. Preferably install and use your own SDK. Then use the same SDK in Project and Modules in Project Settings.
File->Project structure ->SDKs
Choose JDK home path, if no jdk is in the path,
you'll see an icon download jdk
download then ok
Try to copy src and gradle folders and buil.gradle and settings,gradle files in separate folder. Then open this new folder as new project in intellij. Then intellij will propose Import as gradle project... - push it.
If problem remained see you build.gradle
I have a project in eclipse on my laptop that I pushed to Git https://github.com/chrisbramm/LastFM-History-Graph.git
It works fully on my laptop and runs/builds without a problem but on my desktop it doesn't Eclipse gives the error
Error: Could not find or load the main class lastfmhistoryguis.InputPanel
I've tried building the project from:
Project>Build Project
But nothing happened. I've set the PATH variables on this computer to JRE6, JRE7 and JDK 1.7.0 even though these aren't set on my laptop.
I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:\Users\Chris\Downloads folder on my laptop hence it wasn't included in the git tree which I recently brought into the project folder and committed ,but I'm not sure whether I have done it right.
Would this also be causing a problem but there isn't a main argument in there.
I can't work out now, what I need to check/change.
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
tl;dr:
Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.
Project -> Clean
Make sure Project -> Build automatically is active
Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.
Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.
In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.
If this is still not working, have a look at the built-in ErrorLog of Eclipse:
Window -> Show View -> General -> Error Log
In your classpath you're using an absolute path but you've moved the project onto a new machine with quite possibly a different file structure.
In your classpath you should therefore (and probably in general if you're gonna bundle JARS with your project), use relative pathing:
In your .classpath
change
<classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/><classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/>
to
<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>
I did all the things mentioned above, but none of them worked for me
My problem resolved as follows:
Right click on your Project > Properties > JavaBuildPath > Libraries.
Remove the jar file, having a red flag on it.
If problem persists try the solution below. This worked for me when I faced this problem second time:
Right-Click Project > Properties > Java Build Path > Libraries
Remove Library
Add Library. (Choose the JRE System Library )
I faced similar problem in my maven webapp project after spending nearly one hour , I found a solution which worked for me .I typed the following maven command and It worked
mvn clean install -U
I dont know the exact reason behind it.
I am assuming that you had imported the project into your desktop eclipse installation? If that is the case, you should just select Project > Clean. Then rebuild your project. Worked like a charm for me.
VERY CAREFUL: This will unbind your project from the workspace. You'll have to import all your projects again
I had the same issue and solved it using:
Eclipse Mars
Egit
Github
Maven Project
The Problem was that i made my maven project available to github. It moved my project to my github folder.
Solution:
Close Eclipse
Delete the metadata folder inside your workspace
Restart Eclipse
Start screen will be displayed.
Close the start screen
Rightclick into package explorer
Chose "import maven project",
Navigate to your github folder and import the maven project.
After this my project compiled with success.
Check that your project has a builder by either:
check project properties (in the "package explorer", right click on the project, select "properties"), there the second section is "Builders", and it should hold the default "Java Builder"
or look in the ".project" file (in .../workspace/yourProjectName/.project) the section "buildSpec" should not be empty.
There must be other ways, but what I did was:
shut down eclipse
edit the ."project" file to add the "buildSpec" section
restart eclipse
A proper minimal java ".project" file should look like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Well the following worked for me...
Went into the project folder (inside workspace)
Then, deleted the bin folder
Then, Cleaned project / projects (in Eclipse)
built/run from Eclipse.
If your code is good and you know you're having an Eclipse problem, this will solve it.
You could simply delete $yourproject/.classpath , $yourproject/.project , and $yourworkspace/.metadata. Someone else mentioned this option. It will blow up your entire workspace though. Instead:
Delete .classpath and .project from your project
Delete your project in eclipse. DO NOT check delete project
contents on disk.
Now, in a file explorer, go into $yourworkspace/.metadata.
Search for $yourprojectname
Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
Right click your project > properties > Java Build Path > Source tab
Select all source folders, remove.
Add folder, select src (whatever your src folder is called) and add it
Go to libraries tab
Add any jars to your build path here. There should be no more errors on your project now.
Run your project like you normally would.
Similar thing happened to me few times, the only way I knew to fix this was to remove the metadata folder. Fortunately I have found another way.
Try going to project properties > Java Build Path > Order And Export tab > select all (or try to play with check boxes there).
This should cause complete project rebuild and Eclipse to see main class.
Addition: I have noticed that this bug occurs when you have many projects in a work space and some of them is configured wrong(red exclamation mark appears). Fixing project build path and other settings(even if this project is not related to the one you have problems with) should fix an issue.
For me, the reason that this error started showing up was due to classpath getting over the limit on windows. Then I discovered the option "Use temporary JAR to specify classpath (to avoid classpath length limitations)". Selecting this option fixed the problem for me. The option resides in Run/Debug Configuration, Classpath tab, see the image below.
My Main class could not be found or loaded problem is caused by an interesting reason.
In our project, we are using Maven as build tool and my main class extends a class, which is on the class path but its scope was test, while the main class is not under the test package.
If your main class extends a class, first try to run your main class by removing extends part. If it runs, you will at least understand that the problem is not because of run configuration or eclipse but the class, your main class extends.
this could cause of jdk libraries if you had imported into jre
this happen to me , so check installed jre jars
in eclipse click on Windows > Preferences > Java > Installed Jres > click on Jre and edit after that look into jar list make sure none is of jdk or corrupted ,
I had the same problem with correct .classpath file, and soon found actually it's not the .classpath file counted (after I fixed this issue, I replace the workable .classpath file with the original one, the project still worked, which means the .classpath file was not the case)
Since it's a Maven project, all I did is:
mvn eclipse:clean
delete eclipse project
import the project
done
This problem is also caused when you have special characters in your workspace path. I had my workspace in my personal folder and its name was in Greek, so it didn't work. I changed my workspace, now contains only english characters in its path, and now the project is built without any problems.
If You are using eclipse then the following steps will solve your problem:
Go to Run -> Run Configurations -> Main Class Search -> Locate your class manually -> Apply -> Run
I had this error. It was because I had
static void main(String[] args)
instead of
public static void main(String[] args)
I spent nearly an hour trying to figure that out.
Note: The only difference is that I didn't declare main to be public
To solve this error do the following steps:
Step 1: Open the .project file.
Step 2: Check two tags...
a) <buildSpec>
b) <natures>
Step 3: If the above-mentioned tags do not include any content then surely the above error is going to occur.
Step 4: Add the following content to each tag in order to resolve the above error.
For <buildSpec> :
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
For <natures> :
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Step 5: Save your file by hitting ctrl + s.
Step 6: For safe side just close the project once and reopen it.
Step 7: That's it. You are ready to rock!!!
Please mention in comments if the solution was helpful.
Thank you.
I run into the same problem, but in my case it was caused by missing (empty) source folder (it exists in original project, but not in GIT repository because it's empty).
After creating the missing folder everything works.
I ran into this error today because I set up a hello world program and then cut and pasted a new program into the same file. To fix the problem of not finding hello world as the last was called I clicked Run-> Run Configurations and then under Main Class I clicked search and it found my new class name and replaced it with the correct new name in the text that I pasted. This is a newbie problem I know but it is also easy to fix. I hope this helps someone!
Douglas
Mostly this happens, because Eclipse cleans the .class files, but don't build them again. Check the bin folder, it should be empty. Then you should check, is there anything else, which is causing build ti fail. You might have added some jars in classpath, which Eclipse might not be able to find.
Just go to your Package Explorer and press F5, or for some laptops fn+F5. The reason is that eclipse thinks that the files are somewhere, but the files are actually somewhere else. By refreshing it, you put them both on the same page. Don't worry, you won't lose anything, but if you want to be extra careful, just back up the files from your java projects folder to somewhere safe.
These are the simple steps, which helped me to solve this problem.
Close the eclipse
Delete ".metadata" folder in your work-space. (may be hidden folder)
Open the eclipse (it will automatically create ".metadata" folder in your work- space)
Try to run the program.
Check the workspace error log (Windows-> Show View -> Error log). If you see any of the jar's imported is corrupted, remove the corresponding repository folder and re-import again.
2 types of solutions exits for the same.
(1) Go to run configurations: - run->run configurations
In the Classpath tab:
Select Advanced
Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
(2) If first solution is not working then it means the jar you are pointing out to your project is taking the path of your local Maven repo which is not getting updated to your project so better you check the jar from that local maven repo and copy it paste it into new project simply or just download it from any site and configure it into your build path.
I hope it helps.
This problem occurred for me when I deleted a ".jar" file from Eclipse project by right clicking on it and hitting "delete" (not from "Build path").
To solve, I tried the following steps:
1- Right click on the project
2- Build Path --> Configure Build Path
3- Libraries
4- Delete the jar file from there (I see a red mark beside it).
I received this error as well, just after moving some resources. Checking the error log, I saw that Eclipse couldn't make a build since it couldn't remove a file/folder. Try manually removing the "bin" (or whatever it's called for you) folder.
Can be resolved by updating your project.
For example if you use maven and eclipse as you mentioned, do those steps:
Right click on your project
Click on Maven
Click on Update Project...
Click Ok
I just had this problem after first having the problem of Windows 8 refusing to update my path no matter what I set JAVA_HOME to - java -version reported the last JDK instead of the one I stored in JAVA_HOME. I finally got that to work by putting '%JAVA_HOME%/bin;' at the front of the path environment variable instead of at the end. Then I launched Eclipse and all the sudden it could not find my main class when it worked fine before this. What I did to fix it was went into the project properties, removed the existing JRE library from the libraries tab, added a new JRE by selecting the "Add Library" button and then followed the prompts to install JRE 7 as my default JRE. Now all is back to working.
I have a project in eclipse on my laptop that I pushed to Git https://github.com/chrisbramm/LastFM-History-Graph.git
It works fully on my laptop and runs/builds without a problem but on my desktop it doesn't Eclipse gives the error
Error: Could not find or load the main class lastfmhistoryguis.InputPanel
I've tried building the project from:
Project>Build Project
But nothing happened. I've set the PATH variables on this computer to JRE6, JRE7 and JDK 1.7.0 even though these aren't set on my laptop.
I did have Jar file (last.fm-bindings-0.1.1.jar) that was in my .classpath file that was in C:\Users\Chris\Downloads folder on my laptop hence it wasn't included in the git tree which I recently brought into the project folder and committed ,but I'm not sure whether I have done it right.
Would this also be causing a problem but there isn't a main argument in there.
I can't work out now, what I need to check/change.
If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:
"Run As" -> "Java Application."
Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.
If you subsequently MOVE the java class (manually, or however), then again choose
"Run As" -> "Java Application,"
from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.
SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run
"Run As" -> "Java Application"
Eclipse will write a new configuration for the moved class, and the error will go away.
tl;dr:
Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.
Project -> Clean
Make sure Project -> Build automatically is active
Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.
Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.
In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.
If this is still not working, have a look at the built-in ErrorLog of Eclipse:
Window -> Show View -> General -> Error Log
In your classpath you're using an absolute path but you've moved the project onto a new machine with quite possibly a different file structure.
In your classpath you should therefore (and probably in general if you're gonna bundle JARS with your project), use relative pathing:
In your .classpath
change
<classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/><classpathentry kind="lib" path="C:/Users/Chris/Downloads/last.fm-bindings-0.1.1.jar" sourcepath=""/>
to
<classpathentry kind="lib" path="last.fm-bindings-0.1.1.jar"/>
I did all the things mentioned above, but none of them worked for me
My problem resolved as follows:
Right click on your Project > Properties > JavaBuildPath > Libraries.
Remove the jar file, having a red flag on it.
If problem persists try the solution below. This worked for me when I faced this problem second time:
Right-Click Project > Properties > Java Build Path > Libraries
Remove Library
Add Library. (Choose the JRE System Library )
I faced similar problem in my maven webapp project after spending nearly one hour , I found a solution which worked for me .I typed the following maven command and It worked
mvn clean install -U
I dont know the exact reason behind it.
I am assuming that you had imported the project into your desktop eclipse installation? If that is the case, you should just select Project > Clean. Then rebuild your project. Worked like a charm for me.
VERY CAREFUL: This will unbind your project from the workspace. You'll have to import all your projects again
I had the same issue and solved it using:
Eclipse Mars
Egit
Github
Maven Project
The Problem was that i made my maven project available to github. It moved my project to my github folder.
Solution:
Close Eclipse
Delete the metadata folder inside your workspace
Restart Eclipse
Start screen will be displayed.
Close the start screen
Rightclick into package explorer
Chose "import maven project",
Navigate to your github folder and import the maven project.
After this my project compiled with success.
Check that your project has a builder by either:
check project properties (in the "package explorer", right click on the project, select "properties"), there the second section is "Builders", and it should hold the default "Java Builder"
or look in the ".project" file (in .../workspace/yourProjectName/.project) the section "buildSpec" should not be empty.
There must be other ways, but what I did was:
shut down eclipse
edit the ."project" file to add the "buildSpec" section
restart eclipse
A proper minimal java ".project" file should look like:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>myProjectName</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Well the following worked for me...
Went into the project folder (inside workspace)
Then, deleted the bin folder
Then, Cleaned project / projects (in Eclipse)
built/run from Eclipse.
If your code is good and you know you're having an Eclipse problem, this will solve it.
You could simply delete $yourproject/.classpath , $yourproject/.project , and $yourworkspace/.metadata. Someone else mentioned this option. It will blow up your entire workspace though. Instead:
Delete .classpath and .project from your project
Delete your project in eclipse. DO NOT check delete project
contents on disk.
Now, in a file explorer, go into $yourworkspace/.metadata.
Search for $yourprojectname
Delete everything you find. It should be safe-ish to delete anything in the .metadata directory.
In eclipse: File > Import > General > Projects from Folder or Archive > $yourproject > finish
Right click your project > properties > Java Build Path > Source tab
Select all source folders, remove.
Add folder, select src (whatever your src folder is called) and add it
Go to libraries tab
Add any jars to your build path here. There should be no more errors on your project now.
Run your project like you normally would.
Similar thing happened to me few times, the only way I knew to fix this was to remove the metadata folder. Fortunately I have found another way.
Try going to project properties > Java Build Path > Order And Export tab > select all (or try to play with check boxes there).
This should cause complete project rebuild and Eclipse to see main class.
Addition: I have noticed that this bug occurs when you have many projects in a work space and some of them is configured wrong(red exclamation mark appears). Fixing project build path and other settings(even if this project is not related to the one you have problems with) should fix an issue.
For me, the reason that this error started showing up was due to classpath getting over the limit on windows. Then I discovered the option "Use temporary JAR to specify classpath (to avoid classpath length limitations)". Selecting this option fixed the problem for me. The option resides in Run/Debug Configuration, Classpath tab, see the image below.
My Main class could not be found or loaded problem is caused by an interesting reason.
In our project, we are using Maven as build tool and my main class extends a class, which is on the class path but its scope was test, while the main class is not under the test package.
If your main class extends a class, first try to run your main class by removing extends part. If it runs, you will at least understand that the problem is not because of run configuration or eclipse but the class, your main class extends.
this could cause of jdk libraries if you had imported into jre
this happen to me , so check installed jre jars
in eclipse click on Windows > Preferences > Java > Installed Jres > click on Jre and edit after that look into jar list make sure none is of jdk or corrupted ,
I had the same problem with correct .classpath file, and soon found actually it's not the .classpath file counted (after I fixed this issue, I replace the workable .classpath file with the original one, the project still worked, which means the .classpath file was not the case)
Since it's a Maven project, all I did is:
mvn eclipse:clean
delete eclipse project
import the project
done
This problem is also caused when you have special characters in your workspace path. I had my workspace in my personal folder and its name was in Greek, so it didn't work. I changed my workspace, now contains only english characters in its path, and now the project is built without any problems.
If You are using eclipse then the following steps will solve your problem:
Go to Run -> Run Configurations -> Main Class Search -> Locate your class manually -> Apply -> Run
I had this error. It was because I had
static void main(String[] args)
instead of
public static void main(String[] args)
I spent nearly an hour trying to figure that out.
Note: The only difference is that I didn't declare main to be public
To solve this error do the following steps:
Step 1: Open the .project file.
Step 2: Check two tags...
a) <buildSpec>
b) <natures>
Step 3: If the above-mentioned tags do not include any content then surely the above error is going to occur.
Step 4: Add the following content to each tag in order to resolve the above error.
For <buildSpec> :
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
For <natures> :
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Step 5: Save your file by hitting ctrl + s.
Step 6: For safe side just close the project once and reopen it.
Step 7: That's it. You are ready to rock!!!
Please mention in comments if the solution was helpful.
Thank you.
I run into the same problem, but in my case it was caused by missing (empty) source folder (it exists in original project, but not in GIT repository because it's empty).
After creating the missing folder everything works.
I ran into this error today because I set up a hello world program and then cut and pasted a new program into the same file. To fix the problem of not finding hello world as the last was called I clicked Run-> Run Configurations and then under Main Class I clicked search and it found my new class name and replaced it with the correct new name in the text that I pasted. This is a newbie problem I know but it is also easy to fix. I hope this helps someone!
Douglas
Mostly this happens, because Eclipse cleans the .class files, but don't build them again. Check the bin folder, it should be empty. Then you should check, is there anything else, which is causing build ti fail. You might have added some jars in classpath, which Eclipse might not be able to find.
Just go to your Package Explorer and press F5, or for some laptops fn+F5. The reason is that eclipse thinks that the files are somewhere, but the files are actually somewhere else. By refreshing it, you put them both on the same page. Don't worry, you won't lose anything, but if you want to be extra careful, just back up the files from your java projects folder to somewhere safe.
These are the simple steps, which helped me to solve this problem.
Close the eclipse
Delete ".metadata" folder in your work-space. (may be hidden folder)
Open the eclipse (it will automatically create ".metadata" folder in your work- space)
Try to run the program.
Check the workspace error log (Windows-> Show View -> Error log). If you see any of the jar's imported is corrupted, remove the corresponding repository folder and re-import again.
2 types of solutions exits for the same.
(1) Go to run configurations: - run->run configurations
In the Classpath tab:
Select Advanced
Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
(2) If first solution is not working then it means the jar you are pointing out to your project is taking the path of your local Maven repo which is not getting updated to your project so better you check the jar from that local maven repo and copy it paste it into new project simply or just download it from any site and configure it into your build path.
I hope it helps.
This problem occurred for me when I deleted a ".jar" file from Eclipse project by right clicking on it and hitting "delete" (not from "Build path").
To solve, I tried the following steps:
1- Right click on the project
2- Build Path --> Configure Build Path
3- Libraries
4- Delete the jar file from there (I see a red mark beside it).
I received this error as well, just after moving some resources. Checking the error log, I saw that Eclipse couldn't make a build since it couldn't remove a file/folder. Try manually removing the "bin" (or whatever it's called for you) folder.
Can be resolved by updating your project.
For example if you use maven and eclipse as you mentioned, do those steps:
Right click on your project
Click on Maven
Click on Update Project...
Click Ok
I just had this problem after first having the problem of Windows 8 refusing to update my path no matter what I set JAVA_HOME to - java -version reported the last JDK instead of the one I stored in JAVA_HOME. I finally got that to work by putting '%JAVA_HOME%/bin;' at the front of the path environment variable instead of at the end. Then I launched Eclipse and all the sudden it could not find my main class when it worked fine before this. What I did to fix it was went into the project properties, removed the existing JRE library from the libraries tab, added a new JRE by selecting the "Add Library" button and then followed the prompts to install JRE 7 as my default JRE. Now all is back to working.
I have create multi-module maven project in Eclipse IDE (already installed M2Eclipse plugin). There I can build my project successfully. But after build also it shows errors icon in my every module project. What kind of issue it can be?
Thank You.
Without knowing what errors you are seeing I am going to assume that your issue is with eclipse project properties (build path, src directory specification, output classes directory, etc).
You tagged m2eclipse plugin, so you should be able to right click on your project in eclipse select maven->update project configuration. If you do not see that option under maven then you should first see an option called maven->enable dependency management. Click that first and then you should be able to see update project configuration option.
If this does not fix it, then open your project directory containing the pom.xml file in command prompt and run mvn eclipse:eclipse.
One of the above should resolve those pesky error messages provided that your maven build itself is successful.
In eclipse open the Markers Tab (You can open it from Window -> Show View -> searching Markers)
It will show all the related errors with your project. You can identify your problems related to your problem, and solve accordingly. Sometimes it shows Quick Fix option, which is helpful.
For me, the above solution listed out by #CoolBeans was not working out, so i searched further and found out the following:
Go to Problems windows(present besides of Console window). If it is not there then click on Window-> Show View -> Problems
Inside Problems you will be able to see the Errors Description related to your project. In my case it was "java compiler level does not match the version of the installed java project facet". If that is the case for you as well, just follow below steps:
Right Click Project -> Properties
Click Project Facets(present in the left hand side list)
Choose the correct java version in Java Project Facet
Click Apply
That's it!
So I have a maven module (module-A) in IntelliJ. I recently moved some classes from it into another new maven module (module-B) and added a dependency to it. Once I had done this I also modified the signature of a method of one of the moved classes (now in module-B).
I re-imported the poms so that IntelliJ would pick up the dependency changes and ensured all Java imports for the affected files were correct again. Now when I attempt to run my webapp (which depends on the two modules) I get a compile error in a class in module-A calling the modified method of the class in module-B.
The error message is basically saying that that method doesn't exist but believes the old method still exists! I click on the 'make' error and it takes me to the line in a class in module-A calling the modified method...the weird thing is, IntelliJ knows it is fine in the file. i.e. The method is not underlined in red like a compile error would normally be, but the class file name is :(
I compiled it from the command line using 'mvn install' (having also installed module-B) and it is all successful. I have deleted the classes directory in the target of both module-A and module-B and also invalidated IntelliJ's caches and restarted...still happening...any ideas?
I found out that this might help:
File -> Invalidate Caches
Maven Projects -> Reimport should help.
I spent a few hours on this same issue. All of the cleans in the world didn't help.
I deleted my out and target directory in my project and recompiled - that cleared it.
Edit: There is also a magic feature under the file menu: "Invalidate Caches / Restart" This fixes a bunch of "intellij is confused" problems.
Change "Java Compiler" setting in IDEA (User compiler javac in-process) to fix the problem.
Try to mvn clean your projects and mvn install your project B.
The maven integration with intelliJ is kind of buggy when you use the make command directly provided by Intellij. You should directly use the mvn commands, or start them from the maven panel.
I ran across a very similar problem that was driving me insane.
My code would compile fine with the ant task I normally run, but it would not build in IntelliJ, complaining about "Cannot Find Symbol blah blah"
Turns out, you can add "Excluded" files for the compiler. My file somehow got added to that list.
This list is located in File > Settings > Compiler > Excludes (IntelliJ 13)
Following steps should fix this problem :
delete .IntelliJIdea12 / .IdeaIC12 older under c:/user/.../
Invalidate Intelli's cache: File > Invalidate Caches.
This re-indexes your workspace on start-up and also clears your local history. Before you do this, commit or back up all your uncommitted changes.
Once your workspace is back after indexing, do a maven clean install.
when the build is successful, click on Maven Re-imports
This worked for me, I think it should work for others too with a similar problem.
So just stated it up this morning and it's all working!
Last night what I did do was open a new project (intelliJ project) from module-A's and module-B's parent pom and successfully got it to build, possibly doing that and then opening my original project again fixed it somehow...very annoying though
The behavior I see is similar to the one described by the original author.
Error markers show up on the right side of the editor in Intellij 14 and less so in 13.
This happens also if using Scala instead of Java and using SBT instead of Maven.
Also noticed this occurs after the second project is loaded. The first is always fine.
(After much trial and error) Figured it might be caused by Intellij's internal caches becoming somehow corrupt. "Invalidate caches" worked sometime and sometimes did not.
I work with a number of projects using Play! Framework and they use different versions of Scala and lots of dependencies.
I hypothesized the caches become corrupt because the internal key Intellij uses is not good enough to handle situations when the same class, loaded multiple times in different jars, has different signatures, and this results in the editor errors while external builds work fine.
Then the "Changing Ivy Cache Location for sbt projects in IntelliJ IDEA?" post gave the idea to segregate the ivy cache SBT and Intellij use in the hope that the ivy path is part of the internal cache key.
Paul Phillips of TypeSafe provide the "SBT extras" tooling and here I found a way to instruct SBT to use a project based ivy home, cache and SBT boot:
https: //raw.githubusercontent.com/paulp/sbt-extras/master/sbt
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
How to configure Intellij
: see http://content.screencast.com/users/SemanticBeeng/folders/Snagit/media/ec8ec491-6d0c-4691-9598-916a63ba65ef/12.02.2014-08.59.png
Then did the same for the external SBT build to work in sync
: see http://content.screencast.com/users/SemanticBeeng/folders/Snagit/media/dcb287c4-200f-47f3-a937-42865675a22b/12.02.2014-09.01.png
Finally got rid of the user home based .ivy2 and all the contents.
To be sure Intellij does not use this folder I made it readonly.
This was a mistake. Intellij seems to silently fail resolve dependencies if you do this.
This solved the errors and believe they will not come back. :-)
If Intellij guys hear this: please test your releases (Scala, SBT, editor) with all the Play Framework templates from TypeSafe. The problem becomes apparent quickly this way.
I just had a similar issue that was driving me insane. I had done all the other things mentioned in the answers above because I have used Intellij forever, but none worked. In the end I found out that in the maven projects portion of Intellij, one of my modules had been marked "ignore" a simple unignore command from the context menu did the trick.
In my case, I had manually marked a directory as "Test Sources Root" but IDEA marked it on a parent Maven project. Unmarking it in File->Project structure...->Modules fixed the problem.
This could happen if you are using different version of java while building outside IntelljJ. My IntelliJ had java10 and I was using java8 while building at terminal. Changing java version to IntelliJ fixed this issue for me.
I had a very similar behavior. Running (Scala-)tests would always fail due to errors in unrelated java classes during the 'make' step.
It turned out, I had included a 'global' SDK library that collided with one of the dependencies from the project. A proper helpful error message only showed up after I deleted the 'make' step from the test.
I then deleted the duplicate library, re-added the make step to the test and everything is now working fine.
I ran into this problem today after upgrading from 12 to 13.
Later I fixed issue as I used the same name for Project and Module and looks Intellij allows this but cannot handle it correctly.
No idea why setting will impact the compilation, although there is no error in java editor. Should be a bug in version 13.
I was facing a similar issue after upgrading from IntelliJ 12 to 13. After multiple uninstalls and re-installs (of multiple intelliJ versions), numerous cleans and .m2 repository clearing, I finally figured out what my issue was.
In my intelliJ settings, the repositories mentioned in my main POM file could not be connected to. this was in turn due and alternate repository that was mentioned as a part of my pom file.
Once the POM was made to point to the correct repository, all my classes had their compilation issues resolved.
To check if your repositories are being connected to, go to File -> Settings -> Maven -> Repositories
Here, your indexed maven repositories should be connected to successfully. If they are not, then intelliJ will not be able to resolve most 3rd party and module dependencies.
I'm embarrassed to say, but we also had this problem, but it was due to a mistake in our package name.
When creating the packages for a new project I accidentally created a package called "org.package".
My project then had a directory structure like:
/src/main/java/org.package/
Which caused all sorts of havoc with IntilliJ.
Once the correct folder structure was created on the file system, IntelliJ worked great.
/src/main/java/org/package/
Note the difference in /org.package/ vs /org/package/
The fix was i made it javac instead of Ajc and i put 1.8 of course according to your jdk version.
for some reason when i invalidate and restart intellij it was set to be the default !
my version is
This happened to me...what fixed it was realising there was an extra main.iml file in the source directory. Deleting that instantly made the compile errors go away.
None of the above answers worked for me.
In my case, I had to finally create an explicit Maven Run Configuration for the module (with Command Line as "clean install") and then run it.
It is in Run > Edit Configurations
close the project
go-to the project folder and delete idea project file and .iws file
run mvn idea:idea
restart the project.
seems idea keeping the old project dependencies without cleaning even though we run file -> invalidate caches
Setting the proper Java SDK solves the issue
Right click on the project and select "Open Module Settings"
Check if you have the right Java SDK under platform settings
Check the SDK under Modules
Rebuild the project from "Build" menu
Delete the installation directory.
Remove the following directories:
~/.config/JetBrains/
~/.cache/JetBrains/
~/.local/share/JetBrains/
This will remove each and every configuration plus installation of jetbrains tools, be it IDEA, goland,etc.
Now install everything from scratch.
That's the only way it worked for me