Like many Java programmers who acquire "Error: Could non give away or charge primary degree Main" while running Java programme inwards Eclipse, I was also getting the same work recently. The "Error: Could non give away or charge primary class" was rendered me puzzled fifty-fifty later my 10+ years of sense amongst Java errors as well as exceptions. Whenever I run my Java application either past times Run configurations or correct click as well as run equally Java program, I acquire an annoying popup complaining nigh "could non give away or charge the primary class, the programme volition exit". I checked, the projection was compiling fine, I tin run across the .class file for the primary degree inwards the bin directory of Eclipse, as well as I tin fifty-fifty run across the projection as well as output folder added on the classpath of Run configuration, but nevertheless I am getting the "could non give away primary class, programme volition leave of absence error".
I spent skillful ii hours trying everything I could, calling teammates for assist (getting an extra pair of optic e'er helps inwards this sort of situation), searching on the internet, as well as lots of trial as well as error, but the mistake was persistent. The outset clue I got when I debug my Java program. I debug the Java application inwards Eclipse past times correct click as well as choosing "Debug As Java program" as well as constitute that it was throwing ClassNotFoundEexception for of a third-party class.
It was a sort of break-through later wasting such a long fourth dimension but still, the clue wasn't plenty because the degree belongs to i of the subject JAR which was available inwards classpath but somehow Eclipse was non seeing it. My mistake was resolved later deleting existing run configuration where User entry was non pointing to default classpath. Just deleting the run configuration as well as re-creating it past times running the degree past times correct click, "Run As Java program" volition gear upwards the error.
1) Delete the existing run configuration
When you lot run the primary degree equally "Run equally Java Program", it adds the default classpath of the projection equally User entries into Run Configurations's classpath equally shown below.
The work inwards my instance was that my projection also needed native libraries as well as due to other errors I conduct maintain been picayune amongst classpath. It seems spell creating the run configuration past times copying from approximately other project, I deleted the former projection amongst default classpath as well as added novel projection without default classpath. This caused the work equally Eclipse was non detecting whatever subject JAR inwards the project. The work was obscured past times the mistake because it e'er complains nigh primary degree non found, similar to the annoying popup below:
Remember, if your primary degree is subject upon whatever other degree or JAR file as well as if you lot believe everything inwards the classpath, as well as then simply delete the Run configurations as well as Run the primary degree equally Java programme as well as and then edit the run configuration. This solved the work inwards my case. You tin farther read Core Java Volume 1 - Fundamentals to larn to a greater extent than nigh classpath as well as how JVM search as well as charge degree files.
Also, approximately of you lot mightiness non live on getting this popup because I got the popup exclusively on Eclipse Kepler but when I tried to reproduce the effect inwards "Eclipse IDE for Java developers" on Eclipse Luna, I simply got the "Error: Could non give away or charge primary degree Main" inwards reddish as well as bold.
2) Check for missing library
If you lot run across a red exclamation mark inwards your projection way approximately of the libraries which are added inwards construct path is either deleted or moved to other location. Until you lot gear upwards this issue, your projection volition non compile as well as no degree is created inwards the bin directory, thence when you lot run your Java program, Eclipse's classloader volition non give away the primary degree as well as throw this error.
Here is how your projection volition await similar if whatever library from construct path is missing due to whatever argue e.g. someone copied to approximately other directory or you lot unopen the projection from which they were added.
To solve this work simply follow below steps:
3) Debug the program
This volition nation you lot precisely which degree is missing inwards the classpath. I hateful if your primary degree is referring approximately other degree from a third-party library as well as that library is non inwards the classpath, Eclipse volition throw the same "main degree non constitute error". When you lot run the programme inwards debug mode, you lot tin run across precisely which degree the programme is non able to found.
Here is how the debug configuration await like, you lot simply require to click the debug to start debugging your program, the JVM volition start automatically if it's non able to give away the primary degree as well as impress the actual degree as well as mistake inwards console.
There were a duo of to a greater extent than reasons of "Error: Could non give away or charge primary degree Main" inwards Eclipse. I'll like shooting fish in a barrel add together those equally well. If you lot desire to assist you lot tin position your work as well as solution related to Eclipse primary degree non constitute mistake as well as I'll add together those reasons inwards the primary posts. I retrieve to brand this ship service my acquire to house whenever I acquire the ClassNotFoundException or NoClassDefFoundError inwards Eclipse to avoid wasting to a greater extent than fourth dimension inwards future.
Other Eclipse tutorials as well as tips for Java developers
Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 as well as 2
I spent skillful ii hours trying everything I could, calling teammates for assist (getting an extra pair of optic e'er helps inwards this sort of situation), searching on the internet, as well as lots of trial as well as error, but the mistake was persistent. The outset clue I got when I debug my Java program. I debug the Java application inwards Eclipse past times correct click as well as choosing "Debug As Java program" as well as constitute that it was throwing ClassNotFoundEexception for of a third-party class.
It was a sort of break-through later wasting such a long fourth dimension but still, the clue wasn't plenty because the degree belongs to i of the subject JAR which was available inwards classpath but somehow Eclipse was non seeing it. My mistake was resolved later deleting existing run configuration where User entry was non pointing to default classpath. Just deleting the run configuration as well as re-creating it past times running the degree past times correct click, "Run As Java program" volition gear upwards the error.
Solution of Error: Could non give away or charge primary degree inwards Eclipse
Even though I managed to solve the work but it was likewise much a problem for me as well as taken a lot of time. I don't desire to facial expression upwards the same province of affairs again, peculiarly if I am inwards urgency to run my Java programme to debug an urgent production issue. Hence, I conduct maintain decided to jot downwards my sense amongst a duo of to a greater extent than tricks from the past. In this article, I'll portion iii useful tips to solve "could non give away or charge primary degree error" inwards Eclipse.1) Delete the existing run configuration
When you lot run the primary degree equally "Run equally Java Program", it adds the default classpath of the projection equally User entries into Run Configurations's classpath equally shown below.
The work inwards my instance was that my projection also needed native libraries as well as due to other errors I conduct maintain been picayune amongst classpath. It seems spell creating the run configuration past times copying from approximately other project, I deleted the former projection amongst default classpath as well as added novel projection without default classpath. This caused the work equally Eclipse was non detecting whatever subject JAR inwards the project. The work was obscured past times the mistake because it e'er complains nigh primary degree non found, similar to the annoying popup below:
Remember, if your primary degree is subject upon whatever other degree or JAR file as well as if you lot believe everything inwards the classpath, as well as then simply delete the Run configurations as well as Run the primary degree equally Java programme as well as and then edit the run configuration. This solved the work inwards my case. You tin farther read Core Java Volume 1 - Fundamentals to larn to a greater extent than nigh classpath as well as how JVM search as well as charge degree files.
Also, approximately of you lot mightiness non live on getting this popup because I got the popup exclusively on Eclipse Kepler but when I tried to reproduce the effect inwards "Eclipse IDE for Java developers" on Eclipse Luna, I simply got the "Error: Could non give away or charge primary degree Main" inwards reddish as well as bold.
2) Check for missing library
If you lot run across a red exclamation mark inwards your projection way approximately of the libraries which are added inwards construct path is either deleted or moved to other location. Until you lot gear upwards this issue, your projection volition non compile as well as no degree is created inwards the bin directory, thence when you lot run your Java program, Eclipse's classloader volition non give away the primary degree as well as throw this error.
Here is how your projection volition await similar if whatever library from construct path is missing due to whatever argue e.g. someone copied to approximately other directory or you lot unopen the projection from which they were added.
To solve this work simply follow below steps:
- Go to configure construct path
- Check which JAR is missing
- Remove them as well as add together them from the novel location.
You tin farther read Eclipse inwards Action: Influenza A virus subtype H5N1 Guide for the Java Developer to larn to a greater extent than nigh setting as well as edifice Java projects inwards Eclipse.
3) Debug the program
This volition nation you lot precisely which degree is missing inwards the classpath. I hateful if your primary degree is referring approximately other degree from a third-party library as well as that library is non inwards the classpath, Eclipse volition throw the same "main degree non constitute error". When you lot run the programme inwards debug mode, you lot tin run across precisely which degree the programme is non able to found.
Here is how the debug configuration await like, you lot simply require to click the debug to start debugging your program, the JVM volition start automatically if it's non able to give away the primary degree as well as impress the actual degree as well as mistake inwards console.
There were a duo of to a greater extent than reasons of "Error: Could non give away or charge primary degree Main" inwards Eclipse. I'll like shooting fish in a barrel add together those equally well. If you lot desire to assist you lot tin position your work as well as solution related to Eclipse primary degree non constitute mistake as well as I'll add together those reasons inwards the primary posts. I retrieve to brand this ship service my acquire to house whenever I acquire the ClassNotFoundException or NoClassDefFoundError inwards Eclipse to avoid wasting to a greater extent than fourth dimension inwards future.
Other Eclipse tutorials as well as tips for Java developers
- How to connect Eclipse to Oracle database? (see here)
- How to brand executable JAR file inwards Eclipse? (see here)
- How to growth heap size of Java programme running inwards Eclipse? (see here)
- How to gear upwards Unsupported major.minor version 52.0 mistake inwards Eclipse? (see here)
- 3 Maven Eclipse tips for Java developers (see here)
- Top xxx Eclipse keyboard shortcuts for Java programmers (see here)
- How to setup remote debugging inwards Eclipse (see here)
- How to attach rootage code for JAR file inwards Eclipse for debugging? (see here)
- How to gear upwards maven dependency search non working inwards Eclipse? (solution)
- 3 Books to larn as well as master copy Eclipse IDE for Java programming (books)
Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 as well as 2
No comments:
Post a Comment