Friday, July 6, 2012

Solution to fix Exception java.lang.NoClassDefFoundError While running weblogic commands from console


A quick one here. Most of us might experienced this when try to run weblogic.Deployer or any weblogic related command from console or shell prompt you see something like this

C:\>java weblogic.Deployer
Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/Deployer
Caused by: java.lang.ClassNotFoundException: weblogic.Deployer
        at$ Source)
        at Method)
        at 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: weblogic.Deployer.  Program will exit.

The problem is NOT with your installation or configuration but actually java is not able to find classes related to weblogic


The solution is to add the JAR file into the CLASSPATH variable.

C:\> set CLASSPATH=%CLASSPATH%;D:\Oracle\Middleware1035\wlserver_10.3\server\lib\weblogic.jar

Note:  Change above command as per your environment Linux or Windows also i saw some people add the location of the folder to Classpath which will not fix the issue you should provide the name of the JAR file as mentioned above.

You can see in the slide how the error gone by adding CLASSPATH to the environment.