Reputation: 817
I need to produce a jar file that will be used by others as a library (lets call it 'myLib.jar'), thus the jar does not need to be executable. The library depends on some other 3rd-party jars but i will not expect from the ones who use 'myLib.jar' to include them in his/hers Buildpath.
While searching, i found OneJar and followed the 2 steps at the top of the page.
1. Download one-jar-appgen-0.97.jar
Generate application, build, and run it.
$ java -jar one-jar-appgen-0.97.jar
2. Enter project path (project name is last segment): c:/tmp/test-one-jar
Enter java package name: com.example.onejar
$ cd c:/tmp/test-one-jar
$ ant
$ cd build
$ java -jar test-one-jar.jar
test_one_jar main entry point, args=[]
test_one_jar main is running
test_one_jar OK.
Add source code to the src directory, library jars to the lib directory, and rebuild.
Unfortunately, this did not worked for me since when i tried to include 'myLib.jar' in a new project, i was not able to use the expected classes.
So...
Q1: Is OneJar intended only for executable jars? If not how could i achieve what i have described above.
Q2: If OneJar is intended only for executables, is there another way to produce the 'myLib.jar' library?
PS: If there is a need to add more information please let me know, in order to edit my quetsion.
Upvotes: 0
Views: 900
Reputation: 817
All the comments are suggesting to avoid packing the 3rd party libraries into a single jar. There are several good reasons for this:
So, what did i eventually do?
As @rmlan assured me, there is nothing wrong about notifing to the users of the library to add another library to their classpath. Keeping this in mind, i've created the following folder structure (which is actually what many others do) and zipped it in one compressed file:
myLib
-----bin
----------myLib.jar
-----documentation (mentions 'myLib' dependencies among other stuff)
-----lib (contains the 3rd party libraries)
----------thirdPartyLibrary.jar
----------anotherThirdPartyLibrary.jar
-----source (if it is an open source project)
Finally, in my case i could not use maven or another alternative, but if i could this would make the whole procedure much easier.
EDIT: To create 'myLib.jar' I've used eclipse
Upvotes: 0