Link to home
Start Free TrialLog in
Avatar of opike
opike

asked on

Getting NoClassDefFoundError running java on command line

Trying to run a java program from the command line on windows 7. Here's the back file I'm using:

set javahome=C:\progra~1\java\jdk1.6.0_18
set classpath=.;%javahome%;C:\dev\java\ServiceTest\com\roeschter\jsl
set PATH=%PATH%;%javahome%\bin
java -classpath "%classpath%" TelnetEcho

My current directory is c:\dev\java\ServiceTest which contains the compiled file TelnetEcho.class. Here is the full error message:

C:\dev\java\ServiceTest>java -classpath ".;C:\progra~1\java\jdk1.6.0_18;C:\dev\j
ava\ServiceTest\com\roeschter\jsl" TelnetEcho
Exception in thread "main" java.lang.NoClassDefFoundError: TelnetEcho (wrong nam
e: com/roeschter/jsl/TelnetEcho)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: TelnetEcho.  Program will exit.
Avatar of opike
opike

ASKER

Additional info:

There is a package line in the TelnetEcho.java file -
package com.roeschter.jsl;

I tried having the TelnetEcho.class file in both of the following directories:

C:\dev\java\ServiceTest
&
C:\dev\java\Service\Test\com\roeschter\jsl

But to no avail.
Avatar of CEHJ
You need
set classpath=.;C:\dev\java\ServiceTest

Open in new window

Avatar of opike

ASKER

I tried adding C:\dev\java\ServiceTest to the classpath but still getting same error. I didn't think it would make a difference since I'm running the java command from C:\dev\java\ServiceTest and that directory is already covered in the classpath with the dot(.).

C:\dev\java\ServiceTest>java -classpath ".;C:\dev\java\ServiceTest;C:\progra~1\j
ava\jdk1.6.0_18;C:\dev\java\ServiceTest\com\roeschter\jsl" TelnetEcho
Exception in thread "main" java.lang.NoClassDefFoundError: TelnetEcho (wrong nam
e: com/roeschter/jsl/TelnetEcho)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: TelnetEcho.  Program will exit.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of opike

ASKER

Yup I needed to prepend the class name with com.roeschter.jsl.
:-)