building a JAR with internal JAR dependencies

Hope you guys can give me some much sought advice.

I've been attempting to build a JAR file that packages it's own JARs as internal class dependencies, but without exposing those inner JAR dependencies to the outside world. I'm guessing this needs to happen, otherwise the link process for building an Eclipse Android project would fail if not.

So my problem is such:
If I have an internal dependency on say dom4j-1.6.1.jar, I don't want to prevent someone from being able to add my JAR to an Eclipse Android project and including their own dom4j package dependency (possibly a different version). If the internal JAR dependency is exposed they will experience a duplicate resource conflict when attempting to build their project.
e.g. java.lang.IllegalArgumentException: already added: Lcom/google/gson/DefaultTypeAdapters$ByteTypeAdapter;

Here is what I tried to date:
So I have a regular Android project in Eclipse which adds in my packaged JAR as an dependency.

I refered to the Oracle docs, however there is a footnote about the inclusion of JAR files within JARs.

Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

So I decided to try the Fat Jar Eclipse Plug-In from SourceForge.
It's an Eclipse Plug-In for deploying a project into one "fat" executable jar file containing all referenced libraries. References are taken from the project settings, so no manual configuration is necessary.

I did manage to execute my build using this method, however did have to manually hack the packaged JAR file to remove the reference to the annotations package which was causing a conflict with my Android test project by being referenced twice.

So now I am left with a project that builds and executes, but exposes those inner JAR dependency packages to my Android project.

I would appreciate any advice you guys can provide. I hope my explanation is clear enough.

Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by jhansen
4 hours ago
Last post by coty31
3 hours ago
Last post by coy16
59 minutes ago
Last post by jordan97
1 hour ago
Last post by vernie73
2 hours ago