1

I want to create a Java library that depends on a JAR but I want the JAR to be loaded by projects using my library/JAR rather than provided through as a dependency in my library.

The reason I need to do this is that the JAR in question is an Adobe Analytics JAR for Android. These JARs are specific to the project in question but the methods, packages and classes are always named the same in each JAR.

In the C/C++ world you can have separate headers one for the internal build and a public header file for users of the library. Is there a way that this can be done in Java? I usually use Gradle but solutions using other tools would eb very welcome.

TTransmit
  • 3,270
  • 2
  • 28
  • 43

2 Answers2

0

You can include all your dependencies into a single jar and include that uber-jar into third party project.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Same issue as with the other answer. I need to not include the JAR in question in my JAR as if I do that the JAR will be wrong. I need the user of the library to provide a correct version of this JAR that is specific to their project. – TTransmit Sep 22 '16 at 13:13
  • You can just do it. The only requirement for target JVM is to have all dependencied included in runtime classpath. Maven does such thing for you, if you define dependendency scope as `provided`. This causes project to compile, but without the dependencies that supposed to be "provided" at runtime. If using Maven for your build is a viable opiton then go for it. Feature you required is there out of the box – Antoniossss Sep 22 '16 at 15:53
0

Use maven to create JAR with all dependencies (all classes will be included in one big JAR) - How can I create an executable JAR with dependencies using Maven?

Community
  • 1
  • 1
JIV
  • 813
  • 2
  • 12
  • 30
  • I don't think this answers my question. I need to not include the JAR in question in my JAR as if I do that the JAR will be wrong. I need the user of the library to provide a correct version of this JAR that is specific to their project. – TTransmit Sep 22 '16 at 13:13
  • Then tell users to copy their JAR into your application Classpath folder and include it in your start script - http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath – JIV Sep 22 '16 at 13:16