Mohammad Alyan
Mohammad Alyan

Reputation: 11

Running Java Application NoClassDefFoundError

When I run my program from terminal by executing the command java rmiserver.LightBulbServer.class I'm getting NoClassDefFoundError :

Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/LightBulbSe
rver/class
Caused by: java.lang.ClassNotFoundException: rmiserver.LightBulbServer.class
        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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: rmiserver.LightBulbServer.class.  Program will ex
it.

Upvotes: 1

Views: 124

Answers (3)

KevinDTimm
KevinDTimm

Reputation: 14376

You're running the command:

java rmiserver.LightBulbServer.class

when you should be running

java rmiserver.LightBulbServer

Upvotes: 1

mishmash
mishmash

Reputation: 4458

You need to set some variables before Java can do anything on a system. This is why some people create batch files to get their Java programs running without modifying system variables.

But this usually happens because you didn't set the CLASSPATH.

For example, here is something that may or may not work:

set JAVA_HOME=C:\jdk1.5.0_06
set PATH=C:\jdk1.5.0_06\bin;C:\Windows;C:\Windows\System32
set CLASSPATH=.

java -jar myprogram.jar

Or try this command:

java -jar myprogram.jar -classpath .

Upvotes: 0

casablanca
casablanca

Reputation: 70701

You are most likely running the application like this:

java rmiserver.LightBulbServer.class

You shouldn't add the .class extension when running your program; use only the name of the class:

java rmiserver.LightBulbServer

Upvotes: 1

Related Questions