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

Discussion in 'Java' started by Stryder, Oct 15, 2012.

  1. Stryder

    Stryder Guest

    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.
    Stryder, Oct 15, 2012
    #1
    1. Advertising

  2. Stryder

    Jeff Higgins Guest

    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, Oct 15, 2012
    #2
    1. Advertising

  3. Stryder

    Jeff Higgins Guest

    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, Oct 15, 2012
    #3
  4. Stryder

    Jeff Higgins Guest

    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.
    Jeff Higgins, Oct 15, 2012
    #4
  5. Stryder

    Nigel Wade Guest

    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
    Nigel Wade, Oct 15, 2012
    #5
  6. Stryder

    Lew Guest

    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
    Lew, Oct 15, 2012
    #6
  7. Stryder

    Jeff Higgins Guest

    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.:)
    Jeff Higgins, Oct 15, 2012
    #7
  8. Stryder

    Roedy Green Guest

    On Mon, 15 Oct 2012 07:56:44 -0700 (PDT), Stryder
    <> 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.
    Roedy Green, Oct 16, 2012
    #8
  9. Stryder

    Arne Vajhoej Guest

    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
    Arne Vajhoej, Oct 17, 2012
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Hanna
    Replies:
    0
    Views:
    1,305
    Phil Hanna
    Jul 1, 2003
  2. Chandresh Prakash
    Replies:
    1
    Views:
    1,924
    Jeffrey Palm
    Dec 5, 2003
  3. Gabe
    Replies:
    3
    Views:
    1,071
  4. Replies:
    2
    Views:
    1,103
    Mike Schilling
    Mar 2, 2008
  5. Philipp
    Replies:
    18
    Views:
    13,620
    John B. Matthews
    Apr 18, 2009
Loading...

Share This Page