can't find in classpath, but only when running from the jar file

S

Stryder

I'm trying to run a Java class in a jar file. The jar file contains this class:

com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class

The manifest looks like this (not indented).

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_03-b04 (Oracle Corporation)
Main-Class: com.exacttarget.wsdl.partnerapi.PartnerAPIStub

All the main class does is print "hello world". It works (prints "Hello World") if I do this in the classes directory...

java com.exacttarget.wsdl.partnerapi.PartnerAPIStub

This same class is definitely in the jar file as demonstrated by this command...

bash-4.1$ jar tf PartnerAPI-test-client.jar |grep Stub.class
com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class
bash-4.1$

but when I try to run the jar, with the environment exactly as it was when I ran the class separately, using this command...

java -jar PartnerAPI-test-client.jar

I get this error output...

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/axis2/client/Stub

Obviously I'm missing something. Any help would very much be appreciated.
 
J

Jeff Higgins

I'm trying to run a Java class in a jar file. The jar file contains this class:

com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class

The manifest looks like this (not indented).

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_03-b04 (Oracle Corporation)
Main-Class: com.exacttarget.wsdl.partnerapi.PartnerAPIStub

All the main class does is print "hello world". It works (prints "Hello World") if I do this in the classes directory...

java com.exacttarget.wsdl.partnerapi.PartnerAPIStub

This same class is definitely in the jar file as demonstrated by this command...

bash-4.1$ jar tf PartnerAPI-test-client.jar |grep Stub.class
com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class
bash-4.1$

but when I try to run the jar, with the environment exactly as it was when I ran the class separately, using this command...

java -jar PartnerAPI-test-client.jar

I get this error output...

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/axis2/client/Stub

Obviously I'm missing something. Any help would very much be appreciated.
I think you're missing a Class-Path attribute.
Class-Path: The value of this attribute specifies the relative URLs of
the extensions or libraries that this application or extension needs.
URLs are separated by one or more spaces. The application or extension
class loader uses the value of this attribute to construct its internal
search path.
 
J

Jeff Higgins

or a classpath option
java -jar -cp pathtomyaxis2clientjar PartnerAPI-test-client.jar
 
N

Nigel Wade

or a classpath option
java -jar -cp pathtomyaxis2clientjar PartnerAPI-test-client.jar

That won't work. The -cp option is ignored with -jar.

If you use -jar you can only specify a classpath in the Class-Path:
directive in the manifest, as explained in your previous posts.
 
J

Jeff Higgins

A

Arne Vajhoej

I'm trying to run a Java class in a jar file. The jar file contains this class:

com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class

The manifest looks like this (not indented).

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_03-b04 (Oracle Corporation)
Main-Class: com.exacttarget.wsdl.partnerapi.PartnerAPIStub

All the main class does is print "hello world". It works (prints "Hello World") if I do this in the classes directory...

java com.exacttarget.wsdl.partnerapi.PartnerAPIStub

This same class is definitely in the jar file as demonstrated by this command...

bash-4.1$ jar tf PartnerAPI-test-client.jar |grep Stub.class
com/exacttarget/wsdl/partnerapi/PartnerAPIStub.class
bash-4.1$

but when I try to run the jar, with the environment exactly as it was when I ran the class separately, using this command...

java -jar PartnerAPI-test-client.jar

I get this error output...

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/axis2/client/Stub

Obviously I'm missing something. Any help would very much be appreciated.

Other have already told you about the classpath.

But try look at the message:

java.lang.NoClassDefFoundError org/apache/axis2/client/Stub

It actually clearly states that it can not find a class that is
part of Axis2.

The solution follow easily from that analysis.

If you plan on programming in Java for the next 20 years, then you will
see hundreds or thousands of error messages - you need to learn to use
the information provided to resolve problems.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top