GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Issues with cmd java command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Issues with cmd java command" Watch "Issues with cmd java command" New topic
Author

Issues with cmd java command

Jared Malcolm
Ranch Hand

Joined: May 02, 2011
Posts: 54

Can anyone point me towards why I'm getting the error(s) below when trying to run a compiles java class? I'm sure it's something simple that I'm just not seeing... I've already taken and passed my SCJA and I'm just wanting to go to the next step... Just haven't used command line in about a year or so and have forgotten everything.

I've included the two classes I've built just to test everything and the lovely little string of errors below. The quoted text is my cmd prompt that is there just so you can see what I've tried. The javac command works perfect and both classes are compiled....just can't remember how to run the stupid thing.

Parent Class



c:\SCJP>javac com\jared2\Child.java

c:\SCJP>java com\jared2\Child
Exception in thread "main" java.lang.NoClassDefFoundError: com\jared2\Child (wro
ng name: com/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com\jared2\Child. Program will exit.

c:\SCJP>java -classpath . com\jared2\Child
Exception in thread "main" java.lang.NoClassDefFoundError: com\jared2\Child (wro
ng name: com/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com\jared2\Child. Program will exit.

c:\SCJP>cd com\jared2

c:\SCJP\com\jared2>java -classpath . Child
Exception in thread "main" java.lang.NoClassDefFoundError: Child (wrong name: co
m/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Child. Program will exit.

c:\SCJP\com\jared2>java Child
Exception in thread "main" java.lang.NoClassDefFoundError: Child (wrong name: co
m/jared2/Child)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Child. Program will exit.


Thanks for the help! This is making me feel like a ratard.


SCJA 6 (Studying for SCJP 6)
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
\? /!
Shaikh Ali
Ranch Hand

Joined: Jan 26, 2011
Posts: 51
You have to provide the fully qualified name of the class that you are running. Assuming your compiled packages exists in the current directory, try this:

Jared Malcolm
Ranch Hand

Joined: May 02, 2011
Posts: 54

Hauke Ingmar Schmidt wrote:\? /!


My thoughts exactly!

Faraz Kadri wrote:You have to provide the fully qualified name of the class that you are running. Assuming your compiled packages exists in the current directory, try this:



Thanks so much this was the issue! So the final command including the directory structure was...

Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
I wanted to express that all you need to do is replace the invalid package separator by valid separators. \ is invalid, / is valid, . is better.
Jared Malcolm
Ranch Hand

Joined: May 02, 2011
Posts: 54

Hauke Ingmar Schmidt wrote:I wanted to express that all you need to do is replace the invalid package separator by valid separators. \ is invalid, / is valid, . is better.


Good to know. TY.
 
GeeCON Prague 2014
 
subject: Issues with cmd java command