The.Anti.9
The.Anti.9

Reputation: 44648

Java: ClassNotFoundException on class from external jar being instantiated in a thread

I have made a library and exported it to a jar file that I am trying to import into my eclipse project and use. Eclipse says there's no problems but when I debug the application, it enters the new thread and goes to instantiate the object but then throws a ClassNotFoundException

ClassNotFoundException(Throwable).(String, Throwable) line: 217 ClassNotFoundException(Exception).(String, Throwable) line: not available ClassNotFoundException.(String) line: not available
URLClassLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction, AccessControlContext) line: not available [native method] Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available Launcher$ExtClassLoader.findClass(String) line: not available Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available HKServiceListener.run() line: 33 Thread.run() line: not available

The class it's not finding is com.snow.IO.SnowTcpServer. I have included the external jar in my class path and have no compile errors. It only throws at runtime. I even have import com.snow.IO.SnowTcpServer at the top of the file like it should.

Why is it not recognizing my class and how do I get it to do so?

Upvotes: 0

Views: 3420

Answers (3)

The.Anti.9
The.Anti.9

Reputation: 44648

As it turns out, the error was only caused when using the debugger. It had to do with the fact that the code I was stepping into was in an external jar file and not in my source.

Upvotes: 0

NiranjanBhat
NiranjanBhat

Reputation: 1832

If you are running a Enterprise application, please make sure, the Jar is available for deployment also. This needs to be configured additionally.
In case of J2SE application, please check if your jar is visible in run_configuration properties, classpath tab.

If this does not work, then try including the jar file in class path option in the run_configurations option explicitly.

Upvotes: 0

Stanislav Levental
Stanislav Levental

Reputation: 2225

You have problems with your classpath there is no other reason why classload can't find file with your class, try to run your class (compiled class) manually without eclipse using command line

java -cp [your jars separated with ";" - widows or ":" - *nix] com.your.Class

For example:

java -cp /libs/lib1.jar:/libs2/* com.your.Class

Upvotes: 1

Related Questions