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_1 8
set classpath=.;%javahome%;C:\ dev\java\S erviceTest \com\roesc hter\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>ja va -classpath ".;C:\progra~1\java\jdk1.6 .0_18;C:\d ev\j
ava\ServiceTest\com\roesch ter\jsl" TelnetEcho
Exception in thread "main" java.lang.NoClassDefFoundE rror: TelnetEcho (wrong nam
e: com/roeschter/jsl/TelnetEc ho)
at java.lang.ClassLoader.defi neClass1(N ative Method)
at java.lang.ClassLoader.defi neClassCon d(ClassLoa der.java:6 32)
at java.lang.ClassLoader.defi neClass(Cl assLoader. java:616)
at java.security.SecureClassL oader.defi neClass(Se cureClassL oader.java :14
1)
at java.net.URLClassLoader.de fineClass( URLClassLo ader.java: 283)
at java.net.URLClassLoader.ac cess$000(U RLClassLoa der.java:5 8)
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:197)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(UR LClassLoad er.java:19 0)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:307)
at sun.misc.Launcher$AppClass Loader.loa dClass(Lau ncher.java :301)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:248)
Could not find the main class: TelnetEcho. Program will exit.
set javahome=C:\progra~1\java\
set classpath=.;%javahome%;C:\
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>ja
ava\ServiceTest\com\roesch
Exception in thread "main" java.lang.NoClassDefFoundE
e: com/roeschter/jsl/TelnetEc
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
1)
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
Could not find the main class: TelnetEcho. Program will exit.
You need
set classpath=.;C:\dev\java\ServiceTest
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>ja va -classpath ".;C:\dev\java\ServiceTest ;C:\progra ~1\j
ava\jdk1.6.0_18;C:\dev\jav a\ServiceT est\com\ro eschter\js l" TelnetEcho
Exception in thread "main" java.lang.NoClassDefFoundE rror: TelnetEcho (wrong nam
e: com/roeschter/jsl/TelnetEc ho)
at java.lang.ClassLoader.defi neClass1(N ative Method)
at java.lang.ClassLoader.defi neClassCon d(ClassLoa der.java:6 32)
at java.lang.ClassLoader.defi neClass(Cl assLoader. java:616)
at java.security.SecureClassL oader.defi neClass(Se cureClassL oader.java :14
1)
at java.net.URLClassLoader.de fineClass( URLClassLo ader.java: 283)
at java.net.URLClassLoader.ac cess$000(U RLClassLoa der.java:5 8)
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:197)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(UR LClassLoad er.java:19 0)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:307)
at sun.misc.Launcher$AppClass Loader.loa dClass(Lau ncher.java :301)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:248)
Could not find the main class: TelnetEcho. Program will exit.
C:\dev\java\ServiceTest>ja
ava\jdk1.6.0_18;C:\dev\jav
Exception in thread "main" java.lang.NoClassDefFoundE
e: com/roeschter/jsl/TelnetEc
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
1)
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
Could not find the main class: TelnetEcho. Program will exit.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yup I needed to prepend the class name with com.roeschter.jsl.
:-)
ASKER
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\c
But to no avail.