Solved

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

Posted on 2004-10-04
40
333 Views
Last Modified: 2010-03-31

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
0
Comment
Question by:fyness
  • 18
  • 12
  • 10
40 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12215809
There is a problem with the classpath probably. Where is your BasicAuthCLient and from where do you try to run it?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215812
Make sure your classpath is right

set classpath=.;%classpath%
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215821
0
 

Author Comment

by:fyness
ID: 12215823
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
 
LVL 35

Expert Comment

by:girionis
ID: 12215826
Try this:

java -classpath <full path to the root folder of your serviceDeploy/BasicAuthClient> BasicAuthClient
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215831
or even

java -classpath $CLASSPATH:<full path to the root folder of your serviceDeploy/BasicAuthClient> BasicAuthClient
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215835
java -classpath $CLASSPATH:<full path to the root folder of your serviceDeploy/BasicAuthClient> serviceDeploy.BasicAuthClient
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215845
Or

set classpath=.:$classpath

since you're in *nix
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215847
Sorry

classpath=.:$classpath

0
 
LVL 35

Expert Comment

by:girionis
ID: 12215850
export CLASSPATH=%CLASSPATH:.
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215851
export CLASSPATH=$CLASSPATH:.
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215852
Damn those m$ and unix incompatibilites.
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215860
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
 

Author Comment

by:fyness
ID: 12215864
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
 
LVL 35

Expert Comment

by:girionis
ID: 12215868
What is your pwd?
0
 

Author Comment

by:fyness
ID: 12215872
pwd for what?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215874
Please post the output of these

pwd


and

find . -name BasicAuthClient.java
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215876
YOu need to be in the ../ of the serviceDeploy and then run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 

Author Comment

by:fyness
ID: 12215883

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

and

./serviceDeploy/BasicAuthClient.java
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215884
> pwd for what?

Just type pwd and tell us the output
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 35

Expert Comment

by:girionis
ID: 12215890
Try:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215905
In that case

classpath=.:$classpath

should work it you run it before java
0
 

Author Comment

by:fyness
ID: 12215906

Tried  java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient

And got the same
Exception in thread "main" java.lang.NoClassDefFoundError: serviceDeploy/BasicAuthClient
0
 

Author Comment

by:fyness
ID: 12215913
is there a specific jar file i could be missing?
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215915
YOu need to find out where the BasicAuthClient.class file is not the BasicAuthClient.java file
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215919
> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215922
That's true. Run

find . -name BasicAuthClient.class
0
 

Author Comment

by:fyness
ID: 12215930
the basicAuthClient class in teh serviceDeploy folder and its just a java file and class taht i wrote
0
 

Author Comment

by:fyness
ID: 12215939

Did  find . -name BasicAuthClient.class
and got
./serviceDeploy/BasicAuthClient.class
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215953
Can you make sure that the BasicAuthClient is declared exactly like that in the source code? Java is case sensitive.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12215958
Is the package declaration

package serviceDeploy;

in the source file?
0
 

Author Comment

by:fyness
ID: 12215962
as in the class name?

The java complies fine so i doubt its a typo of the class
0
 

Author Comment

by:fyness
ID: 12215986
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
 
LVL 35

Expert Comment

by:girionis
ID: 12216014
> 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
 
LVL 35

Accepted Solution

by:
girionis earned 125 total points
ID: 12216018
Also try this to compile:

javac -d . BasicAuthClient.java

and then to run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient
0
 

Author Comment

by:fyness
ID: 12216021
sorry its actually serviceDeploy package not deployment, that was an older verison of the class
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12216034
Well spotted ;-) the package name is wrong
0
 

Author Comment

by:fyness
ID: 12216037
Hey thats great!

this worked
javac -d . BasicAuthClient.java

and then to run it:

java -classpath $CLASSPATH:. serviceDeploy.BasicAuthClient


thanks!!!!
0
 
LVL 35

Expert Comment

by:girionis
ID: 12216128
:) I think CEJH deserves some points too for helping identify the problem.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12220344
Generous of you g. but don't worry - you spotted the wrong package name ;-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now