Avatar of Ronayne
Ronayne

asked on 

java.lang.NoClassDefFoundError

Hi experts, I get this error when I try to execute a java file. Thanks

D:\DS\dsSoapLab>java gmit.CalcClient
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis/utils
/Options
        at gmit.CalcClient.main(CalcClient.java:12)

the java file:
package gmit;

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

import javax.xml.rpc.ParameterMode;

public class CalcClient{
      public static void main(String [] args) throws Exception{
            Options options = new Options(args);

            String endpoint = "http://localhost:8080/axis/Calculator.jws";

            // Do argument checking
             args = options.getRemainingArgs();

             if (args == null || args.length != 3){
                  System.err.println("Usage: CalcClient <add|subtract arg1 arg2");
                 return;
             }

             String method = args[0];
             if (!(method.equals("add") || method.equals("subtract"))) {
                  System.err.println("Usage: CalcClient <add|subtract arg1 arg2");
                  return;
             }

            // Make the call
             Integer i1 = new Integer(args[1]);
             Integer i2 = new Integer(args[2]);

             Service service = new Service();
             Call call = (Call) service.createCall();

        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName( method );
        call.addParameter("op1", XMLType.XSD_INT, ParameterMode.IN);
        call.addParameter("op2", XMLType.XSD_INT, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_INT);

        Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });

        System.out.println("Got result : " + ret);
      }
}
Java

Avatar of undefined
Last Comment
Ronayne
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Sounds like the Apache Axis libraries not in classpath. Place jars in all lib\ext directories
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

Type:
D:\DS\dsSoapLab>java -cp .;<location of axis.jar> gmit.CalcClient
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

More particularly, your runtime classpath does not correspond to your compile time one. If you want to keep the number of copies of these jars down to a minimum, you can avoid following my first suggestion but instead, you'll have to set the runtime classpath to the same one that was used at compile time.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Here is some general info on the classpath:

http://mindprod.com/jgloss/classpath.html
Avatar of Ronayne
Ronayne

ASKER

This is my classpath

C:\>set classpath
CLASSPATH=.;C:\j2sdk1.4.0_03\lib;c:\rmi\gmit;C:\Program Files\Apache Group\Tomca
t 4.1\server\lib\catalina.jar;D:\xml-xindice-1.0\java\lib\xindice.jar;c:\castor-
0.9.5.2.jar;d:\DS\dsSoapLab\gmit
Avatar of Ronayne
Ronayne

ASKER


I have axis.jar in my jre/lib/ext folder in my jdk
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>d:\DS\dsSoapLab\gmit

That one's not actually right in fact. Should be

d:\DS\dsSoapLab

But forget that for the moment. Before running from that directory , type

set classpath=

and try it again
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>and try it again

Meaning running, not compiling
Avatar of Ronayne
Ronayne

ASKER


I tried that and I got the same error
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Now there's no classpath, run this program with the parameter "java.ext.dirs" and tell me the output:

public class Props {
      
      public static void main(String[] args) {
            if (args.length > 0) {
                  for (int i = 0; i < args.length; i++) {
                        System.out.println(System.getProperty(args[0]));
                  }
            }
            else {
                  System.getProperties().list(System.out);
            }
      }
}
Avatar of Ronayne
Ronayne

ASKER


I removed the classpath from my environmental variable settings but still the same error
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You shouldn't have done that really, but no matter - you posted it here so you can restore it. You can unset/set the classpath per instance of a command window, so there's no need to do that. Anyway, leave it empty for the moment and compile and run the above.
Avatar of Ronayne
Ronayne

ASKER


I ran that program and got this:
c:\program files\java\j2re1.4.0_03\lib\ext
Avatar of Ronayne
Ronayne

ASKER


i saved a copy in notepad anyway, i wouldnt be so daft as to stop myself from undoing the changes I make
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

OK. That's where that Axis jar should be
Avatar of Ronayne
Ronayne

ASKER


that is brilliant, thank you very much, how does your code work?
Avatar of Ronayne
Ronayne

ASKER


I thought jdk automatically looks in jre/lib/ext for jar files?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>I thought jdk automatically looks in jre/lib/ext for jar files?

Yes it does. Your axis.jar must not have been there originally
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ronayne
Ronayne

ASKER


my axis jar file was always in jre/lib/ext, even when it threw my original error, thats why im confused. Id just like to know why it did'nt work  
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not sure at the moment. Keep the jar where it is and reset the classpath (in environment variables) to *exactly* what it was before and we'll see if we can break it again ;-)
Avatar of Ronayne
Ronayne

ASKER


ive done that and everything is working fine now, just one of those things I geuss.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

OK - we'll let it ride ;-)
Avatar of Ronayne
Ronayne

ASKER

Fine by me
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo