Solved

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

Posted on 2004-10-04
40
334 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 69
split string containing \r\n in Java 46 38
Apps blocked by Java 9 60
java jdbc batch example 8 20
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

912 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

23 Experts available now in Live!

Get 1:1 Help Now