Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19355 > unrolled thread

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

Started byStryder <stryder100@gmail.com>
First post2012-10-15 07:56 -0700
Last post2012-10-17 11:52 -0400
Articles 9 — 6 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  can't find in classpath, but only when running from the jar file Stryder <stryder100@gmail.com> - 2012-10-15 07:56 -0700
    Re: can't find in classpath, but only when running from the jar file Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 11:22 -0400
      Re: can't find in classpath, but only when running from the jar file Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 11:31 -0400
      Re: can't find in classpath, but only when running from the jar file Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 11:51 -0400
        Re: can't find in classpath, but only when running from the jar file Nigel Wade <nmw@ion.le.ac.uk> - 2012-10-15 17:04 +0100
        Re: can't find in classpath, but only when running from the jar file Lew <lewbloch@gmail.com> - 2012-10-15 09:16 -0700
        Re: can't find in classpath, but only when running from the jar file Jeff Higgins <jeff@invalid.invalid> - 2012-10-15 13:00 -0400
    Re: can't find in classpath, but only when running from the jar file Roedy Green <see_website@mindprod.com.invalid> - 2012-10-15 19:43 -0700
    Re: can't find in classpath, but only when running from the jar file Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 11:52 -0400

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

FromStryder <stryder100@gmail.com>
Date2012-10-15 07:56 -0700
Subjectcan't find in classpath, but only when running from the jar file
Message-ID<4a7b7c26-806b-4a3d-8fed-f56e35ba8d76@googlegroups.com>
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.

[toc] | [next] | [standalone]


#19356

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 11:22 -0400
Message-ID<k5h9b5$2sa$1@dont-email.me>
In reply to#19355
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.

[toc] | [prev] | [next] | [standalone]


#19357

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 11:31 -0400
Message-ID<k5h9sh$6fa$1@dont-email.me>
In reply to#19356
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>

[toc] | [prev] | [next] | [standalone]


#19358

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 11:51 -0400
Message-ID<k5hb21$ee6$1@dont-email.me>
In reply to#19356
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.

[toc] | [prev] | [next] | [standalone]


#19359

FromNigel Wade <nmw@ion.le.ac.uk>
Date2012-10-15 17:04 +0100
Message-ID<ae2qfnFie08U1@mid.individual.net>
In reply to#19358
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

[toc] | [prev] | [next] | [standalone]


#19363

FromLew <lewbloch@gmail.com>
Date2012-10-15 09:16 -0700
Message-ID<9e320b94-16b3-4c54-9cd0-6ca39e6540de@googlegroups.com>
In reply to#19358
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

[toc] | [prev] | [next] | [standalone]


#19364

FromJeff Higgins <jeff@invalid.invalid>
Date2012-10-15 13:00 -0400
Message-ID<k5hf33$9fd$1@dont-email.me>
In reply to#19358
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.:)

[toc] | [prev] | [next] | [standalone]


#19390

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-10-15 19:43 -0700
Message-ID<66ip78502o3l3htj21lk7fve8mlj0emddn@4ax.com>
In reply to#19355
On Mon, 15 Oct 2012 07:56:44 -0700 (PDT), Stryder
<stryder100@gmail.com> 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. 

[toc] | [prev] | [next] | [standalone]


#19409

FromArne Vajhoej <arne@vajhoej.dk>
Date2012-10-17 11:52 -0400
Message-ID<507ed448$0$289$14726298@news.sunsite.dk>
In reply to#19355
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


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web