Exception in thread "main" java.lang.NoClassDefFoundError:


Hi,

I’ve created a BasicAuthClient class and it complies fine but when I try to run it i.e. java serviceDeploy.BasicAuthClient I’m getting the following error

Exception in thread "main" java.lang.NoClassDefFoundError: serviceDeploy/BasicAuthClient
 
Can anyone help me with this problem?

Thanks,

Suzy
fynessAsked:
Who is Participating?
 
girionisConnect With a Mentor Commented:
Also try this to compile:

javac -d . BasicAuthClient.java

and then to run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 
girionisCommented:
There is a problem with the classpath probably. Where is your BasicAuthCLient and from where do you try to run it?
0
 
CEHJCommented:
Make sure your classpath is right

set classpath=.;%classpath%
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
fynessAuthor Commented:
i;ve set my classpaths in the bashrc with CLASSPATH = 'usr/..../tools.jar:/usr/,,, etc

the paths work fine for tomcat so syntax should be fine, unless im missing a jar or something?
0
 
girionisCommented:
Try this:

java -classpath <full path to the root folder of your serviceDeploy/BasicAuthClient> BasicAuthClient
0
 
girionisCommented:
or even

java -classpath $CLASSPATH:<full path to the root folder of your serviceDeploy/BasicAuthClient> BasicAuthClient
0
 
girionisCommented:
java -classpath $CLASSPATH:<full path to the root folder of your serviceDeploy/BasicAuthClient> serviceDeploy.BasicAuthClient
0
 
CEHJCommented:
Or

set classpath=.:$classpath

since you're in *nix
0
 
CEHJCommented:
Sorry

classpath=.:$classpath

0
 
girionisCommented:
export CLASSPATH=%CLASSPATH:.
0
 
girionisCommented:
export CLASSPATH=$CLASSPATH:.
0
 
girionisCommented:
Damn those m$ and unix incompatibilites.
0
 
girionisCommented:
fyness actually non of the above paths (that contain the dot (.)) will work if you are not in the root folder of the serviceDeploy/BasicAuthClient
0
 
fynessAuthor Commented:
Did that and got this error

Exception in thread "main" java.lang.NoClassDefFoundError: serviceDeploy/BasicAuthClient (wrong name: BasicAuthClient)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

The class is definity in the serviceDeploy folder and called BasicAuthClient
0
 
girionisCommented:
What is your pwd?
0
 
fynessAuthor Commented:
pwd for what?
0
 
CEHJCommented:
Please post the output of these

pwd


and

find . -name BasicAuthClient.java
0
 
girionisCommented:
YOu need to be in the ../ of the serviceDeploy and then run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 
fynessAuthor Commented:

pwd
/usr/local/jakarta-tomcat-5.0.27/webapps/axis

and

./serviceDeploy/BasicAuthClient.java
0
 
girionisCommented:
> pwd for what?

Just type pwd and tell us the output
0
 
girionisCommented:
Try:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 
CEHJCommented:
In that case

classpath=.:$classpath

should work it you run it before java
0
 
fynessAuthor Commented:

Tried  java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient

And got the same
Exception in thread "main" java.lang.NoClassDefFoundError: serviceDeploy/BasicAuthClient
0
 
fynessAuthor Commented:
is there a specific jar file i could be missing?
0
 
girionisCommented:
YOu need to find out where the BasicAuthClient.class file is not the BasicAuthClient.java file
0
 
girionisCommented:
> is there a specific jar file i could be missing?

What is the BasicAuthClient? Is it a class you wrote or is it inside a jar file you got from somewhere?
0
 
CEHJCommented:
That's true. Run

find . -name BasicAuthClient.class
0
 
fynessAuthor Commented:
the basicAuthClient class in teh serviceDeploy folder and its just a java file and class taht i wrote
0
 
fynessAuthor Commented:

Did  find . -name BasicAuthClient.class
and got
./serviceDeploy/BasicAuthClient.class
0
 
girionisCommented:
Can you make sure that the BasicAuthClient is declared exactly like that in the source code? Java is case sensitive.
0
 
CEHJCommented:
Is the package declaration

package serviceDeploy;

in the source file?
0
 
fynessAuthor Commented:
as in the class name?

The java complies fine so i doubt its a typo of the class
0
 
fynessAuthor Commented:
Yeah declared the packages and so forth. If it helps heres is the code of the BasicAuthClient class. Its a web service client

package serviceDeployment;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.net.URL;

import org.apache.axis.encoding.XMLType;
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;


public class BasicAuthClient {
      
      
      public static void main (String args[]) {
            
            try {
                  if (args == null) {
                        System.out.println("Usage: java serviceDeployment.BasicAuthClient "
                         + "<username> <password>");
                         System.exit(0);
                  }
                  
                  //For HTTP Basic Authenticatio
                  String username = args[0];
                  String password = args[1];
                  
                  String endpointURL = "http://localhost:8080/axis/services/AuthTest";
                  
                  //Method Name to invoke for the BankModulusChecker Web Service
                  
                  String methodName = "validateTest";
                  
                  //Create the Service call
                  
                  Service service = new Service();
                  Call call = (Call) service.createCall();
                  call.setTargetEndpointAddress(new java.net.URL(endpointURL));
                  call.setOperationName(new QName("BankModulusChecker" , methodName));
                  call.addParameter("testvalue" , XMLType.XSD_STRING, ParameterMode.IN);
            
                  call.setReturnType(XMLType.XSD_BOOLEAN);
                  
                  //We now call the username and pwd
                  call.setUsername(username);
                  call.setPassword(password);
                  
                  
                              
                  //Setup the parameters
                  Object[] params = new Object[] {
                              "test"};
                  
                  Boolean valid = (Boolean) call.invoke(params);
                  
                  //Print out the result
                  System.out.println("The test value is " + valid.toString());
                  
            }catch (Exception e) {
                  System.err.println(e.toString());
                  
            }
            
            
      }
0
 
girionisCommented:
> package serviceDeployment;

change it to

package serviceDeploy;

But it is weird how the compiled class got into the serviceDeplyo folder. Did you create the folder put it there by hand?
0
 
fynessAuthor Commented:
sorry its actually serviceDeploy package not deployment, that was an older verison of the class
0
 
CEHJCommented:
Well spotted ;-) the package name is wrong
0
 
fynessAuthor Commented:
Hey thats great!

this worked
javac -d . BasicAuthClient.java

and then to run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient


thanks!!!!
0
 
girionisCommented:
:) I think CEJH deserves some points too for helping identify the problem.
0
 
CEHJCommented:
Generous of you g. but don't worry - you spotted the wrong package name ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.