Executable jar file problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric

    Executable jar file problem

    Problem:
    --------
    I'm trying to create an executable jar file. I can do so as long as
    I don't use the "package" statement in my source code. Once I put the
    package statement in I can't execute the jar file.

    Here is the criteria of what I am working with:
    -----------------------------------------------
    Working directory:
    ------------------
    /home/emartin/testArea

    Classpath is set to:
    --------------------
    export CLASSPATH=$CLAS SPATH:.:/usr/java/lib/tools.jar:/usr/java/lib/dt.jar:/usr/java/lib/htmlconver
    ter.jar:/home/emartin

    Source file name: test.java

    Contents of test.java :
    --------------------------------
    package testArea;

    import java.io.*;
    import java.net.*;
    import java.util.*;

    public class test
    {
    public test (){}

    public static void main (String[] args)
    {
    try
    {
    System.out.prin tln( "test.main( ) Hey there!");

    }
    catch (Exception e)
    {
    e.printStackTra ce();
    }
    }
    }

    --------------------------------

    Contents of ManifestHeader. txt :
    --------------------------------
    Main-Class: testArea.test

    Build Procedure:
    ----------------
    javac test.java

    Builds a test.class file which runs fine as follows:
    ----------------------------------------------------
    java testArea.test

    Build an executable jar file using the manifest file as follows:
    ----------------------------------------------------------------
    jar cmf ManifestHeader. txt test.jar test.class

    Execute the jar file as follows:
    --------------------------------
    java -jar test.jar

    I get the following error when trying to execute the jar file:
    --------------------------------------------------------------
    Exception in thread "main" java.lang.NoCla ssDefFoundError :
    testArea/test

    It's acting like it can't understand what the CLASSPATH is set to.
    I've tried various combinations of compiling and running with
    the -classpath arguement to javac and java, respectively.
    But nothing seems to work.
    Has anyone else had problems with this or am I missing something
    very fundamental?

    Regards,
    --Eric
  • Raymond DeCampo

    #2
    Re: Executable jar file problem

    Eric wrote:[color=blue]
    >
    > Build an executable jar file using the manifest file as follows:
    > ----------------------------------------------------------------
    > jar cmf ManifestHeader. txt test.jar test.class
    >
    >
    > I get the following error when trying to execute the jar file:
    > --------------------------------------------------------------
    > Exception in thread "main" java.lang.NoCla ssDefFoundError :
    > testArea/test
    >
    > It's acting like it can't understand what the CLASSPATH is set to.
    > I've tried various combinations of compiling and running with
    > the -classpath arguement to javac and java, respectively.
    > But nothing seems to work.
    > Has anyone else had problems with this or am I missing something
    > very fundamental?[/color]

    Eric,

    The problem is that the class file should be in a directory dictated by
    the package name. In this case, test.class should be in testArea/.
    Arrange your file system so you can execute the jar command like so:

    jar cmf ManifestHeader. txt test.jar testArea/test.class

    HTH,
    Ray

    --
    XML is the programmer's duct tape.

    Comment

    • Eric

      #3
      Re: Executable jar file problem

      Raymond DeCampo <rdecampo@spam. twcny.spam.rr.s pam.com.spam> wrote in message news:<JNHAc.191 732$hY.175345@t wister.nyroc.rr .com>...[color=blue]
      > Eric wrote:[color=green]
      > >
      > > Build an executable jar file using the manifest file as follows:
      > > ----------------------------------------------------------------
      > > jar cmf ManifestHeader. txt test.jar test.class
      > >
      > >
      > > I get the following error when trying to execute the jar file:
      > > --------------------------------------------------------------
      > > Exception in thread "main" java.lang.NoCla ssDefFoundError :
      > > testArea/test
      > >
      > > It's acting like it can't understand what the CLASSPATH is set to.
      > > I've tried various combinations of compiling and running with
      > > the -classpath arguement to javac and java, respectively.
      > > But nothing seems to work.
      > > Has anyone else had problems with this or am I missing something
      > > very fundamental?[/color]
      >
      > Eric,
      >
      > The problem is that the class file should be in a directory dictated by
      > the package name. In this case, test.class should be in testArea/.
      > Arrange your file system so you can execute the jar command like so:
      >
      > jar cmf ManifestHeader. txt test.jar testArea/test.class
      >
      > HTH,
      > Ray[/color]

      Ray,
      Thanks for taking the time to review my post and giving me some
      feedback. It worked beautifully!! I now have an executable jar file.
      It also enlighted me to that fundamental piece that I was missing.
      Thanks again Ray, it's appreciated.
      --Eric

      Comment

      • roopa_gh

        #4
        Re: Executable jar file problem

        Hi Eric,

        Hope you got solutions to your problem.If so please guide me how did
        do solve it?I am creating an executable jar file butI don't have an
        package in my application.

        Working Directory
        --------------
        D:\Mp3ToRingTon e
        Main Class is :mp3Player

        Contents of Manifest file
        ---------------------
        Manifest-Version: 1.0
        Main-Class: mp3player
        Created-By: Roopa

        <I have left 2 blank lines>

        when i run
        java mp3player it launch the application without any problem

        Command used to Buid the Jar file
        ---------------
        jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class

        Execute the Jar
        java -jar MyRingRone.jar

        I get the following error Exception in thread "main
        java.lang.NoCla ssDefFoundError : MyFileFilter

        MyFileFilter is class, which i am using in mp3player.java. And when
        unpack the jar file MyFileFilter.cl ass exists. I don't understand wha
        is the problem.



        Any suggestion or guidence would be highly appriciated.
        Thanks in advance
        Roopa.










        Raymond DeCampo wrote:[color=blue]
        > *Eric wrote:[color=green]
        > >
        > > Build an executable jar file using the manifest file as follows:
        > > ----------------------------------------------------------------
        > > jar cmf ManifestHeader. txt test.jar test.class
        > >
        > >
        > > I get the following error when trying to execute the jar file:
        > > --------------------------------------------------------------
        > > Exception in thread "main" java.lang.NoCla ssDefFoundError :
        > > testArea/test
        > >
        > > It's acting like it can't understand what the CLASSPATH is set to.
        > > I've tried various combinations of compiling and running with
        > > the -classpath arguement to javac and java, respectively.
        > > But nothing seems to work.
        > > Has anyone else had problems with this or am I missing something
        > > very fundamental?[/color]
        >
        > Eric,
        >
        > The problem is that the class file should be in a directory dictate
        > by
        > the package name. In this case, test.class should be in testArea/.
        > Arrange your file system so you can execute the jar command like so:
        >
        > jar cmf ManifestHeader. txt test.jar testArea/test.class
        >
        > HTH,
        > Ray
        >
        > --
        > XML is the programmer's duct tape.[/color]
        -
        roopa_g
        -----------------------------------------------------------------------
        Posted via http://www.codecomments.co
        -----------------------------------------------------------------------

        Comment

        • Giridhar Nandigam

          #5
          Re: Executable jar file problem

          Hello

          Please verify the Classpath. It should include the pwd(Present Working
          Directory) representd by ".".

          i.e...
          CLASSPATH = c:/j2sdk/lib;.;

          May be that will help.

          roopa_gh <roopa_gh.18rrp o@mail.codecomm ents.com> wrote in message news:<4b575beeb bf30c42162197ab 4c083d76@news.t henewsgroups.co m>...[color=blue]
          > Hi Eric,
          >
          > Hope you got solutions to your problem.If so please guide me how did u
          > do solve it?I am creating an executable jar file butI don't have any
          > package in my application.
          >
          > Working Directory
          > --------------
          > D:\Mp3ToRingTon e
          > Main Class is :mp3Player
          >
          > Contents of Manifest file
          > ---------------------
          > Manifest-Version: 1.0
          > Main-Class: mp3player
          > Created-By: Roopa
          >
          > <I have left 2 blank lines>
          >
          > when i run
          > java mp3player it launch the application without any problem
          >
          > Command used to Buid the Jar file
          > ---------------
          > jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class
          >
          > Execute the Jar
          > java -jar MyRingRone.jar
          >
          > I get the following error Exception in thread "main"
          > java.lang.NoCla ssDefFoundError : MyFileFilter
          >
          > MyFileFilter is class, which i am using in mp3player.java. And when i
          > unpack the jar file MyFileFilter.cl ass exists. I don't understand what
          > is the problem.
          >
          >
          >
          > Any suggestion or guidence would be highly appriciated.
          > Thanks in advance
          > Roopa.
          >
          >
          >
          >
          >
          >
          >
          >
          >
          >
          > Raymond DeCampo wrote:[color=green]
          > > *Eric wrote:[color=darkred]
          > > >
          > > > Build an executable jar file using the manifest file as follows:
          > > > ----------------------------------------------------------------
          > > > jar cmf ManifestHeader. txt test.jar test.class
          > > >
          > > >
          > > > I get the following error when trying to execute the jar file:
          > > > --------------------------------------------------------------
          > > > Exception in thread "main" java.lang.NoCla ssDefFoundError :
          > > > testArea/test
          > > >
          > > > It's acting like it can't understand what the CLASSPATH is set to.
          > > > I've tried various combinations of compiling and running with
          > > > the -classpath arguement to javac and java, respectively.
          > > > But nothing seems to work.
          > > > Has anyone else had problems with this or am I missing something
          > > > very fundamental?[/color]
          > >
          > > Eric,
          > >
          > > The problem is that the class file should be in a directory dictated
          > > by
          > > the package name. In this case, test.class should be in testArea/.
          > > Arrange your file system so you can execute the jar command like so:
          > >
          > > jar cmf ManifestHeader. txt test.jar testArea/test.class
          > >
          > > HTH,
          > > Ray
          > >
          > > --
          > > XML is the programmer's duct tape. *[/color][/color]

          Comment

          • Raymond DeCampo

            #6
            Re: Executable jar file problem

            roopa_gh wrote:[color=blue]
            > Hi Eric,
            >
            > Hope you got solutions to your problem.If so please guide me how did u
            > do solve it?I am creating an executable jar file butI don't have any
            > package in my application.
            >
            > Working Directory
            > --------------
            > D:\Mp3ToRingTon e
            > Main Class is :mp3Player
            >
            > Contents of Manifest file
            > ---------------------
            > Manifest-Version: 1.0
            > Main-Class: mp3player
            > Created-By: Roopa
            >
            > <I have left 2 blank lines>
            >
            > when i run
            > java mp3player it launch the application without any problem
            >
            > Command used to Buid the Jar file
            > ---------------
            > jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class
            >
            > Execute the Jar
            > java -jar MyRingRone.jar
            >
            > I get the following error Exception in thread "main"
            > java.lang.NoCla ssDefFoundError : MyFileFilter
            >
            > MyFileFilter is class, which i am using in mp3player.java. And when i
            > unpack the jar file MyFileFilter.cl ass exists. I don't understand what
            > is the problem.
            >[/color]

            Roopa,

            Note that a NoClassDefFound Error is different from a
            ClassNotFoundEx ception. An ClassNotFoundEx ception usually indicates a
            classpath problem. A NoClassDefFound Error indicates a more complex
            problem, e.g., a corrupt or incompatible class file.

            Ray

            --
            XML is the programmer's duct tape.

            Comment

            • roopa_gh

              #7
              Re: Executable jar file problem

              Hi Gridhar,
              Thanks for your kind reply. I have cehcked with classpath. still i a
              having same problem. But when i run application without jar it work
              fine. Any more suggestion?

              Thanks in advance,
              Roopa.

              Please verify the Classpath. It should include the pwd(Present Working
              Directory) representd by ".".

              i.e...
              CLASSPATH = c:/j2sdk/lib;.;

              May be that will help.

              roopa_gh <roopa_gh.18rrp o@mail.codecomm ents.com> wrote in messag
              news:<4b575beeb bf30c42162197ab 4c083d76@news.t henewsgroups.co m>...[color=darkred][color=blue]
              > Hi Eric,
              >
              > Hope you got solutions to your problem.If so please guide me how di[/color]
              u[color=blue]
              > do solve it?I am creating an executable jar file butI don't have any
              > package in my application.
              >
              > Working Directory
              > --------------
              > D:\Mp3ToRingTon e
              > Main Class is :mp3Player
              >
              > Contents of Manifest file
              > ---------------------
              > Manifest-Version: 1.0
              > Main-Class: mp3player
              > Created-By: Roopa
              >
              > <I have left 2 blank lines>
              >
              > when i run
              > java mp3player it launch the application without any problem
              >
              > Command used to Buid the Jar file
              > ---------------
              > jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class
              >
              > Execute the Jar
              > java -jar MyRingRone.jar
              >
              > I get the following error Exception in thread "main"
              > java.lang.NoCla ssDefFoundError : MyFileFilter
              >
              > MyFileFilter is class, which i am using in mp3player.java. And whe[/color]
              i[color=blue]
              > unpack the jar file MyFileFilter.cl ass exists. I don't understan[/color]
              what[color=blue]
              > is the problem.
              >
              >
              >
              > Any suggestion or guidence would be highly appriciated.
              > Thanks in advance
              > Roopa.
              >
              >
              >
              >
              >
              >
              >
              >
              >
              >
              > Raymond DeCampo wrote: [/B[/color]
              -
              roopa_g
              -----------------------------------------------------------------------
              Posted via http://www.codecomments.co
              -----------------------------------------------------------------------

              Comment

              • roopa_gh

                #8
                Re: Executable jar file problem

                Hi Ray,

                Thanks for your kind response.
                You said A NoClassDefFound Error indicates a more complex
                problem, e.g., a corrupt or incompatible class file.

                But my application works fine without jar. Is there is any chance of
                file getting corrupted at the time of jaring the file? Please guide
                me.

                Thanks in advance,
                Roopa.

                [color=blue]
                > Hi Eric,
                >
                > Hope you got solutions to your problem.If so please guide me how did[/color]
                u[color=blue]
                > do solve it?I am creating an executable jar file butI don't have any
                > package in my application.
                >
                > Working Directory
                > --------------
                > D:\Mp3ToRingTon e
                > Main Class is :mp3Player
                >
                > Contents of Manifest file
                > ---------------------
                > Manifest-Version: 1.0
                > Main-Class: mp3player
                > Created-By: Roopa
                >
                > <I have left 2 blank lines>
                >
                > when i run
                > java mp3player it launch the application without any problem
                >
                > Command used to Buid the Jar file
                > ---------------
                > jar -cvmf META-INF/Manifest.mf MyRingTone.jar mp3player.class
                >
                > Execute the Jar
                > java -jar MyRingRone.jar
                >
                > I get the following error Exception in thread "main"
                > java.lang.NoCla ssDefFoundError : MyFileFilter
                >
                > MyFileFilter is class, which i am using in mp3player.java. And when[/color]
                i[color=blue]
                > unpack the jar file MyFileFilter.cl ass exists. I don't understand[/color]
                what[color=blue]
                > is the problem.
                >[/color][/color]

                Roopa,

                Note that a NoClassDefFound Error is different from a
                ClassNotFoundEx ception. An ClassNotFoundEx ception usually indicates a
                classpath problem. A NoClassDefFound Error indicates a more complex
                problem, e.g., a corrupt or incompatible class file.

                Ray

                --
                XML is the programmer's duct tape. [/B]
                --
                roopa_gh
                ------------------------------------------------------------------------
                Posted via http://www.codecomments.com
                ------------------------------------------------------------------------

                Comment

                • Raymond DeCampo

                  #9
                  Re: Executable jar file problem

                  roopa_gh wrote:[color=blue]
                  > Hi Ray,
                  >
                  > Thanks for your kind response.
                  > You said A NoClassDefFound Error indicates a more complex
                  > problem, e.g., a corrupt or incompatible class file.
                  >
                  > But my application works fine without jar. Is there is any chance of
                  > file getting corrupted at the time of jaring the file? Please guide
                  > me.
                  >[/color]

                  Roopa,

                  I would try these two things:

                  1) Post exactly what you have done to create the jar file, starting from
                  nothing but the source code. Include details like the file system
                  structure, the manifest file, etc. (Note that your OP claimed that
                  MyFileFilter.cl ass was in the jar file but it was not in the command you
                  used to create the jar.) There have been a couple of recent posts like
                  this, search Google for a guideline.

                  2) Create an empty directory and unpack your jar there using the jar
                  program (use the x option). Set the classpath to the classpath in your
                  manifest prepended by the current directory. Try to execute your main
                  class from the manifest.

                  Ray

                  --
                  XML is the programmer's duct tape.

                  Comment

                  • roopa_gh

                    #10
                    Re: Executable jar file problem

                    I would try these two things:

                    1) Post exactly what you have done to create the jar file, startin
                    from
                    nothing but the source code. Include details like the file system
                    structure, the manifest file, etc. (Note that your OP claimed that
                    MyFileFilter.cl ass was in the jar file but it was not in the comman
                    you
                    used to create the jar.) There have been a couple of recent post
                    like
                    this, search Google for a guideline.

                    2) Create an empty directory and unpack your jar there using the jar
                    program (use the x option). Set the classpath to the classpath i
                    your
                    manifest prepended by the current directory. Try to execute your main
                    class from the manifest.

                    Ray

                    Hi Ray,

                    Thanks for the guidence.With your guidence i am able to solve th
                    problem. Now i am able to lunch my application with jar file. I hav
                    stucked with other problem

                    In my application i am using third party tool.
                    For ex: ThirdPartyTool. jar which i am placing under D:\Roopa

                    And I have java application which i have jared say MyApplication.j ar
                    This also i placed under D:\Roopa.

                    when i lunch the application with the command
                    java -jar MyApplication.j ar working fine.

                    But in my application for conversion of file it has to invok
                    "ThirdPartyTool .jar".

                    so i am setting classpath="%CLA SSPATH%";D:\Roo pa\ThirdPartyTo ol.jar;
                    and then running java -jar Myapplication.j ar it launches th
                    application but conversion is not happening.

                    But it works fine without jar. when i run
                    java MainClass launches and conversion takes place.
                    where i am going wrong. Please guide me.

                    Thanks for your time.
                    Roopa.






                    --
                    XML is the programmer's duct tape. [/B
                    -
                    roopa_g
                    -----------------------------------------------------------------------
                    Posted via http://www.codecomments.co
                    -----------------------------------------------------------------------

                    Comment

                    Working...