Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > can't find in classpath, but only when running from the jar file

Reply
Thread Tools

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

 
 
Stryder
Guest
Posts: n/a
 
      10-15-2012
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.

 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      10-15-2012
On 10/15/2012 10:56 AM, Stryder wrote:
> 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.
 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      10-15-2012
On 10/15/2012 11:22 AM, Jeff Higgins wrote:
> On 10/15/2012 10:56 AM, Stryder wrote:
>> 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.

<http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html>
 
Reply With Quote
 
Jeff Higgins
Guest
Posts: n/a
 
      10-15-2012
On 10/15/2012 11:22 AM, Jeff Higgins wrote:
> On 10/15/2012 10:56 AM, Stryder wrote:
>> 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


or a classpath option
java -jar -cp pathtomyaxis2clientjar 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.


 
Reply With Quote
 
Nigel Wade
Guest
Posts: n/a
 
      10-15-2012
On 15/10/12 16:51, Jeff Higgins wrote:

> 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.

--
Nigel Wade
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-15-2012
Jeff Higgins wrote:
> or a classpath option
> java -jar -cp pathtomyaxis2clientjar PartnerAPI-test-client.jar


Java will ignore the classpath option in this command.

--
Lew
 
Reply With Quote
 
Jeff Higgins
Guest
Posts: n/a
 
      10-15-2012
On 10/15/2012 11:51 AM, Jeff Higgins wrote:
> On 10/15/2012 11:22 AM, Jeff Higgins wrote:
>> On 10/15/2012 10:56 AM, Stryder wrote:


>>> 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

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

I've supplied misinformation here.

Quoting from the java - The Java Application Launcher manual
<http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html#options>

-jar
[snip]
"When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored. "
[snip]

Thanks to Nigel and Lew for catching this.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-16-2012
On Mon, 15 Oct 2012 07:56:44 -0700 (PDT), Stryder
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

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


see http://mindprod.com/jgloss/jar.html
http://mindprod.com/jgloss/jarexe.html

Jars ignore the SET=classpath. You need to put a classpath inside the
jar with a Class-Path attribute in the manifest.
--
Roedy Green Canadian Mind Products http://mindprod.com
The iPhone 5 is a low end Rolex.


 
Reply With Quote
 
Arne Vajhoej
Guest
Posts: n/a
 
      10-17-2012
On 10/15/2012 10:56 AM, Stryder wrote:
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
Jar file cannot find main class - gfSetup.jar (0/1) James Alan Farrell Java 6 01-09-2004 12:40 PM



Advertisments