Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   can't find in classpath, but only when running from the jar file (http://www.velocityreviews.com/forums/t953386-cant-find-in-classpath-but-only-when-running-from-the-jar-file.html)

Stryder 10-15-2012 02:56 PM

can't find in classpath, but only when running from the jar file
 
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.


Jeff Higgins 10-15-2012 03:22 PM

Re: can't find in classpath, but only when running from the jar file
 
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.

Jeff Higgins 10-15-2012 03:31 PM

Re: can't find in classpath, but only when running from the jar file
 
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>

Jeff Higgins 10-15-2012 03:51 PM

Re: can't find in classpath, but only when running from the jar file
 
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.



Nigel Wade 10-15-2012 04:04 PM

Re: can't find in classpath, but only when running from the jar file
 
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

Lew 10-15-2012 04:16 PM

Re: can't find in classpath, but only when running from the jar file
 
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

Jeff Higgins 10-15-2012 05:00 PM

Re: can't find in classpath, but only when running from the jar file
 
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.:)

Roedy Green 10-16-2012 02:43 AM

Re: can't find in classpath, but only when running from the jar file
 
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.



Arne Vajhoej 10-17-2012 03:52 PM

Re: can't find in classpath, but only when running from the jar file
 
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





All times are GMT. The time now is 08:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57