One-Jar doesn't load library jars from /lib?

Help
2008-03-14
2013-05-23
  • Steve Perkins

    Steve Perkins - 2008-03-14

    Hi folks,

    I'm brand-new to using One-Jar, which is an excellent tool in theory. I'd rather distribute my Java application as a single jar file in order to make the user's work as simple as possible. After getting the build process to work correctly (it took a while), I had One-Jar working great - and then something changed and my libraries are no longer accessible. I'm hoping someone else recognizes the problem and can give me a boot in the right direction. I did inspect the source code of JarClassLoader.java, but a lot of it's over my head and the activity didn't really aid my understanding of what the issue might be.

    Here's the structure breakdown:
    MainJar.jar
    /com
    /lib
         /lib.jar
              /META-INF
                   MANIFEST.MF
              library1.jar
              library2.jar

    /main
         /main.jar
              /com
                   /simontuffs
                        /onejar
                             (bunch of Boot/Handler/JarClassLoader class files)
              /META-INF
                   MANIFEST.MF (blank file)

    /META-INF
         MANIFEST.MF (shown below)
    .version
    OneJar.class

    MANIFEST.MF in the root META-INF folder reads:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.)
    Main-Class: com.simontuffs.onejar.Boot
    One-Jar-Main-Class: com.mycompany.forms.MainForm
    Class-Path: library1.jar library2.jar
    (newline)

    Obviously I'm missing something. I've tried changing the Class-Path attribute, including library1.jar and library2.jar in the /main directory, etc etc etc. The libraries are recognized and loaded just fine if I put them in the same folder as MainJar.jar, but to me that indicates the native class loader is being used and the One-Jar class loader is not being run. Any suggestions?

    -Steve

     
    • Steve Perkins

      Steve Perkins - 2008-03-14

      My apologies, the formatting of the folder structure got mangled when it posted. I've re-formatted it below.
      MainJar.jar
      /com
      .../simontuffs
      ....../onejar
      .........(bunch of Boot/Handler/JarClassLoader class files)

      /lib
      .../lib.jar
      ....../META-INF
      .........MANIFEST.MF
      ......library1.jar
      ......library2.jar

      /main
      .../main.jar
      ....../com
      ........./mycompany
      ............/forms
      ...............MainForm.class
      ....../META-INF
      .........MANIFEST.MF (blank file)

      /META-INF
      ...MANIFEST.MF (shown below)
      ... .version
      ... OneJar.class

      -Steve

       
      • P. Simon Tuffs

        P. Simon Tuffs - 2008-03-14

        It looks like you're not using the Ant task to build your one-jar (in the latest 0.96 release).  The correct structure under lib should be

        lib/
          library1.jar
          library2.jar

        It is not necessary to jar up your library jars.

        Good luck.

        Simon.

         
        • Steve Perkins

          Steve Perkins - 2008-03-14

          Simon,

          I am using the Ant task (with some modifications to build.xml), but you are absolutely, 100% correct about the problem. My build.xml was jar-ing my two libraries into lib.jar. I changed it to simply copy the libraries into /lib and it works exactly as I want it to. Thank you for responding so quickly and for taking the time to solve my problem.

          -Steve

           
    • Reginald Johnson

      Steve,
        I'm having the some problem you were, and would like to try the solution Simon pointed out.  How did you copy the libraries into /lib?  Once you one-jar'ed the files was lib in the root of the one-jar'ed jar?

       
    • Reginald Johnson

         First, I just want to thank Simon for coming up with such a great tool.  It has helped a lot in achieving my eventual goal of deploying an app across Linux and Windows.
         I figured out the solution to the problem I ran into that I posted about above.  I'll post it here in case somebody else runs into the same thing.  Once I looked into the source code and realized one-jar inherits from jar, I figured out that anything you can do to jar, you can do to one-jar.  So, to answer my original question, to include a file under the lib directory just do the following inside the one-jar tag section:

      <lib>
         <fileset dir="${classeslin}/lib"/>
      </lib>

      I hope that makes sense.

       
      • Steve Perkins

        Steve Perkins - 2008-03-17

        Hi Reggie,

        Your solution is basically what I use in the Ant task. The example Ant task does have a <lib> tag, and I just changed its environment variable to point to my own libs folder.

        -Steve

         

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks