Error: Could Non Uncovering Or Charge Nous Bird Inwards Coffee [Solved]

Error: Could non abide by or charge original degree HelloWorld comes when y'all are trying to run your Java plan using coffee command alongside the original degree equally HelloWorld but Java is non able to abide by the class. In companionship to solve this error, y'all must know how Java abide by together with loads the classes, that's a petty flake complex theme for beginners, but nosotros volition affect the same base of operations here. For the curious reader, I would propose reading my post How Classpath plant inwards Java, a must read for a beginner. For now, y'all simply hollo back that at that topographic point is an surroundings variable called CLASSPATH which includes directories where Java looks for all degree files together with if it doesn't abide by your original degree at that topographic point together with then it throws "Error: Could non abide by or charge original degree XXX", where XXX is the cite of your original class.

Since many Java programmer is straightaway started programming using Eclipse they human face upwardly this final result when they offset attempt to run their Java plan from command line. In Eclipse, it's slow to compile together with run the plan because Eclipse takes tending of all Classpath setup, but when y'all run your Java plan from command line, CLASSPATH surroundings variable comes inwards picture.

Personally, I don't similar this surroundings variable together with doesn't define inwards my surroundings variable, because its confusing together with root of thus many classpath related issue. Instead, I usage -cp or -classpath choice alongside java command to run my program. This means y'all ever know which JARs are included inwards your classpath.


For beginners, roughly other of import thing to sympathise is the difference betwixt PATH together with CLASSPATH, y'all must know that PATH is used locate organisation executable, commands or .exe, .dll files (in Windows) together with .so files (in Linux). It is likewise used to locate native libraries used past times your Java program. While, CLASSPATH is used to locate the degree file or JAR files. It's Java degree loader who looked into CLASSPATH for loading classes.


Coming dorsum to the work inwards hand, if y'all are a beginner inwards Java, who are able to run the plan from Eclipse but getting "Error: Could non abide by or charge original degree HelloWorld" when trying to run the same plan from the command business together with then follow the steps given hither to solve it.



Solving Error: Could non abide by or charge original degree HelloWorld 

Unfortunately beginner's majority similar HelloWorld program for our testing, interestingly I receive got named it HelloHP together with it resides inwards a packet called "dto". I receive got purposefully chosen a degree alongside a packet instead of HelloWorld inwards the default packet because many programmers acquire "Could non abide by or charge original class" fault when they attempt to run a degree which is within a package.

package dto; /**  * Simple Java plan to demonstrate next fault  * Error :Could non abide by or charge original degree  *   * @author Javin Paul  */ public class HelloHP {      public static void main(String args[]) {         System.out.println("My offset plan inwards Java, HelloWorld !!");             }  }

When y'all run this from Eclipse, past times Right click on the root file together with Choosing "Run equally Java Program", it volition run fine together with impress next line:

My offset plan inwards Java, HelloWorld !!

Everything equally expected, Now nosotros volition attempt to run same Java plan from command line. Since I am using Maven alongside Eclipse, its create procedure creates degree files inwards project_directory\target\classes directory. If y'all are non using Maven alongside Eclipse, together with then y'all tin sack come across the degree file created past times Eclipse's Java compiler inwards project_directory\bin. It doesn't affair how those degree files are created, but, what is of import is the place of the degree file.

If your degree is within a non-default package e.g. "dto" inwards our representative together with then compiler the volition pose the HelloHP.class file, which contains Java bytecode inwards a directory named "dto". In our representative the total cite of degree dto.HelloHP together with it is acquaint inwards C:\Users\WINDOWS 8\workspace\Demo\target\classes\dto. So inwards the offset try, I acquire at that topographic point together with execute coffee command to launch my program, equally seen below:

C:\Users\WINDOWS 8\workspace\Demo\target\classes\dto>java HelloHP Error: Could non abide by or charge original class HelloHP

Do y'all come across the error? It's coming because the total cite of the degree should hold upwardly dto.HelloHP together with non HelloHP. So let's right this fault together with attempt to run the same command from the same place but this fourth dimension alongside fully qualified name:

C:\Users\WINDOWS 8\workspace\Demo\target\classes\dto>java dto.HelloHP Error: Could non abide by or charge original class dto.HelloHP

Still same error, right. Why? because I don't receive got whatever CLASSPATH surroundings variable, neither I am using -classpath or -cp choice to propose the path, So by default Java is solely searching inwards the electrical flow directory. It is looking for dto/HelloHP.class but since nosotros are already within dto, it is  not able to abide by the class. So, what should nosotros arrive at now? let's acquire to the rear directory "C:\Users\WINDOWS 8\workspace\Demo\target\classes" together with execute the same command, this time, it should work:

C:\Users\WINDOWS 8\workspace\Demo\target\classes\dto>cd ..  C:\Users\WINDOWS 8\workspace\Demo\target\classes>java dto.HelloHP My offset plan inwards Java, HelloWorld !!

Bingo!!, our plan ran successfully because, without whatever hint close where to abide by degree files, Java is past times default looking into the electrical flow directory, denoted past times . (dot) together with able to locate ./dto/HelloHP.class.

Now, what if y'all desire to run this plan from whatever other directory? Well, for that role whether nosotros need to define CLASSPATH or simply usage -classpath or -cp option. I similar the minute choice because it's easier to command together with change. Also, remember, it overrides whatever CLASSPATH surroundings variable. If y'all similar to set CLASSPATH surroundings variable inwards Windows, come across that tutorial.

Now let's run the plan target directory offset without using -classpath option:

C:\Users\WINDOWS 8\workspace\Demo\target\classes>cd ..  C:\Users\WINDOWS 8\workspace\Demo\target>java dto.HelloHP Error: Could non abide by or charge original class dto.HelloHP

You tin sack come across nosotros are i time again started getting the same error, Why? because Java is notwithstanding looking into the electrical flow directory together with at that topographic point is no .\target\dto\HelloHP.class there, equally it's i flat downwardly e.g. .\target\classes\dto\HelloHP.class

Now let's run the same command using -classpath choice from target directory itself:

C:\Users\WINDOWS 8\workspace\Demo\target>java -cp ./classes;. dto.HelloHP My offset plan inwards Java, HelloWorld !!

Bingo!!, our plan ran successfully i time again because straightaway Java is likewise looking at ./classes directory together with at that topographic point it is able to abide by dto\HelloHP.class file.

There are many ways Error: Could non abide by or charge original degree HelloWorld manifests itself, but if y'all know the basics of Java Classpath, y'all can easily form out the problem. Most of the fourth dimension y'all simply need to either right your CLASSPATH surroundings variable or run your plan alongside java -cp or -classpath option. By the way, at that topographic point are to a greater extent than to it e.g. Main degree defined inwards the manifest.mf file together with that's why I propose reading close How Classpath plant inwards Java (see the link inwards the offset paragraph).

Summary

If y'all are getting "Error: Could non abide by or charge original degree XXX", where XXX is the cite of your original degree land running Java plan together with then arrive at this to solve that error:

1) If y'all are running Java plan right from the directory where .class file is together with y'all receive got CLASSPATH surroundings variable defined together with then brand certain it include electrical flow directory. (dot). You tin sack include it equally set CLASSPATH=%CLASSPATH%;. inwards Windows together with export CLASSPATH = ${CLASSPATH}:. (see the separator, inwards Windows it's;(semicolon) land inwards Linux it is (colon), likewise authorities annotation nosotros receive got included electrical flow directory inwards existing classpath. If y'all notwithstanding human face upwardly the final result of setting classpath, come across this step past times measuring guide to laid the classpath. Same thing applies if y'all are running your plan using -cp or -classpath option.


2) If y'all are running Java plan from the directory, your .class file is together with y'all don't receive got whatever CLASSPATH or -cp choice together with then cheque whether your degree is the inwards the packet or not. If it's the inwards the packet together with then acquire exterior of the packet directory together with run coffee command alongside fully qualified cite e.g. if your plan is com.abc packet together with then runs next command from the rear directory of "com"

java com.abc.HelloWorld

without whatever classpath hints, Java volition human face into the electrical flow directory together with search for com\abc\HelloWorld.class inwards Windows, thus if com directory exists inwards your electrical flow directory, your plan volition run otherwise y'all volition acquire "Error: Could non abide by or charge original degree dto.HelloHP".


3) You tin sack run your Java plan from anywhere alongside the assistance of proper CLASSPATH or coffee -cp choice equally shown below:

java -cp C:\test\;. com.abc.HelloWorld


If y'all notwithstanding facing whatever final result simply cheque whether y'all receive got accidentally using CLASSPATH surroundings variable, y'all tin sack cheque this inwards Windows past times running echo %CLASSPATH% command together with inwards Linux past times running echo $CLASSPATH. If CLASSPATH is nonempty together with then it volition impress its value otherwise simply echo the same command.

4) If y'all are running inwards Java version 1.6 or 1.5, together with then instead of receiving "Error: Could non abide by or charge original class", y'all volition get Exception inwards thread "main" java.lang.NoClassDefFoundError: HelloWorld. It's solely from JDK 1.7 onward nosotros are started receiving this novel error. The solution is just same, every flake of give-and-take applies to that representative equally well. So if y'all are non able to solve that work past times next steps here, arrive at allow me know together with I volition attempt to locomote alongside y'all to troubleshoot the problem.

Here is the screenshot of how I tried to reproduce together with solve the fault equally discussed inwards the previous paragraph:

 Could non abide by or charge original degree HelloWorld Error: Could non abide by or charge original degree inwards Java [Solved]



That's all close how to solve "Error: Could non abide by or charge original degree HelloWorld" inwards Java. Classpath is petty confusing theme to master, but y'all volition sympathise it i time y'all started writing together with running roughly Java program. If y'all are notwithstanding non able to laid upwardly your work together with then post a comment at that topographic point alongside what y'all receive got tried together with nosotros volition attempt to troubleshoot together. My destination is non simply to give y'all solution but likewise brand y'all able to explicate why the solution is working together with CLASSPATH basics are real of import for a Java developer. I receive got seen many programmers getting frustrated, losing involvement inwards Java due to diverse PATH together with CLASSPATH issues e.g. NoClassDefFoundError together with ClassNotFoundException together with this is my humble endeavor to choose them dorsum together with empower alongside practical knowledge. Hope y'all understand.


Further Reading
Building debugging together with troubleshooting science is non slow together with it takes lots of exercise together with sense to understand, reproduce together with solve the error. If y'all are novel Java developer together with then y'all offset pick a majority to larn Java from start to end, but if y'all are intermediate Java developer together with then y'all should human face at the next resources to railroad train your debugging skill.

Understanding the Java Virtual Machine: Class Loading together with Reflection
The Complete Java MasterClass
Core Java for the Impatient - Covers Java SE 8

0 Response to "Error: Could Non Uncovering Or Charge Nous Bird Inwards Coffee [Solved]"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel