Results 1 to 10 of 10
  1. #1
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Packaging Custom Library in Java Program

    I have a custom library I made to make things easier for myself. I used it in a small program in NetBeans and it works fine. When I try to clean and build, it says it can't find the methods from my Library class. How do I get the library packaged into the jar?

    I've looked it up, and I've found numerous similar examples, but I don't know much about Java packaging and jars, so the solutions don't help. This page looks the most similar to my problem, but the answer is too confusing for me. I apologize for my ignorance.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Packaging Custom Library in Java Program

    I normally distribute them as two (or more) .jar files, where the 'main' .jar file mentions the other .jar(s) in its manifest entry on its class path ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Packaging Custom Library in Java Program

    So that makes it so if I put both jars in the same place that it'll work?

    That's better than nothing, but is there a way to package one inside the other? Or maybe package them both in another jar? I'm thinking it might be similar to packaging images in the jar?

    Again, I'm totally new at this and clueless. Thanks.

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Packaging Custom Library in Java Program

    Eclipse can package jars inside executable jars, but this is some Eclipse trickery, not standard Java stuff. I believe it uses a custom classloader to achieve this feat.

    I set up one of my projects to build with Maven. The parent POM creates a zip file, which contains my executable jar and a lib directory with the other jars. Then the user just needs to include the lib dir in their classpath when they run my jar.
    Get in the habit of using standard Java naming conventions!

  5. #5
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Packaging Custom Library in Java Program

    So you're saying it would be easier if I was using Eclipse?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,743
    Rep Power
    5

    Default Re: Packaging Custom Library in Java Program

    Note: whenever you start a sentence with "so you're saying...", you have a very big chance of not understanding what you have read and are thus wrong.

    the only thing kjrum is saying is some tricks that Eclipse offers, he's not making any kind of recommendation.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Packaging Custom Library in Java Program

    Quote Originally Posted by gimbal2 View Post
    Note: whenever you start a sentence with "so you're saying...", you have a very big chance of not understanding what you have read and are thus wrong.

    the only thing kjrum is saying is some tricks that Eclipse offers, he's not making any kind of recommendation.
    Both true assumptions. Thank you for clearing that up.

  8. #8
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Packaging Custom Library in Java Program

    You can use JarSplice, it allows you to pack libraries and natives into your jar file.
    1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111

  9. #9
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Packaging Custom Library in Java Program

    The problem was that I hadn't ever built my library. Once I did that, the program built without error. It was still difficult to use though.

    Quote Originally Posted by zFollette View Post
    You can use JarSplice, it allows you to pack libraries and natives into your jar file.
    This tool is AWESOME! It's simple and easy and does everything for me. Even creating .exe for Windows. Thanks for this resource. It solved many different problems I've been having/would have.

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,743
    Rep Power
    5

    Default Re: Packaging Custom Library in Java Program

    Agreed; that tool is awesome! Thanks for sharing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Importing a custom library
    By chrondog in forum New To Java
    Replies: 4
    Last Post: 02-21-2013, 09:38 AM
  2. custom tag library to populate a listbox
    By niteangell21 in forum New To Java
    Replies: 0
    Last Post: 11-29-2010, 08:37 PM
  3. Packaging program
    By billq in forum New To Java
    Replies: 2
    Last Post: 07-02-2010, 05:05 AM
  4. Diff program/library for Java
    By Singing Boyo in forum New To Java
    Replies: 0
    Last Post: 06-05-2010, 01:53 AM
  5. Packaging and Running Java Apps
    By JL4 in forum New To Java
    Replies: 1
    Last Post: 04-08-2009, 07:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •