0

I am working on a java application that depends on several jars such as args4j, groovy, jasperreports, etc.

I would like to package just my code into a run-able jar while still referencing these external jars, perhaps by piping them into the one with my code somehow. Is there a way that I can do this?

I am fairly new to java, so simpler answers are probably better. Also, I plan to run this application from Windows command-line.

edit: Just to farther clarify, I have some compile-time dependencies and some run-time dependencies. I want the run-time dependencies to not be packaged into my jar so that the jar size is not so big.

edit 2: This is not a duplicate. Firstly, I am not using eclipse. Secondly, I am not trying to package external jars within the jar I am creating. Instead, I would like to keep them outside of the jar I am making and somehow specify to use these external jars when I go to run my jar.

Edge
  • 1
  • 2
  • You say "*to package just my code*" and then "*by piping them into the one **with** my code*". Seems like a self-contradiction. The way I understood your needs - you need to look into using [Maven](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html) or [Gradle](https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html). – PM 77-1 Jul 14 '16 at 13:33
  • Maybe you are misunderstanding me. I would like the classes that I wrote to be placed in a jar that does not include the jars they depend on. At run-time, I would like to specify these dependency jars in the command line, perhaps piping them in somehow. Sorry if this is seems like a stupid question, I am new to Java. – Edge Jul 14 '16 at 13:52
  • In such case my advice to look at Maven and/or Gradle stands. – PM 77-1 Jul 14 '16 at 14:01
  • I already have. Again, I am a java beginner. Most of the documentation for Maven and Gradle seems to be aimed for experienced java programmers and is difficult to understand. I am looking for a simple answer. – Edge Jul 14 '16 at 14:31
  • How do you expect those "*external*" JARs to appear on customer's system? – PM 77-1 Jul 14 '16 at 15:00
  • That is not an issue, but the reason for wanting this separation is simply a company preference. For the purpose of organizing our in-house binaries and such. – Edge Jul 14 '16 at 15:20
  • Are you asking [this](http://stackoverflow.com/questions/183292/classpath-including-jar-within-a-jar) question? – PM 77-1 Jul 14 '16 at 15:27
  • No, if I understand correctly what he is asking. I am not trying to reference jars contained in another jar. I am trying to separate the dependent jars from a jar that contains just my code, and be able to specify when I run my jar that it uses dependent jars located at "c:\...\somedirectory" when I go to run mine. – Edge Jul 14 '16 at 15:47
  • Then just add this *somedirectory* to your [`CLASSPATH`](http://kevinboone.net/classpath.html). – PM 77-1 Jul 14 '16 at 16:32
  • So for example _java -jar myjar.jar -cp c:\...\somedirectory_ ? – Edge Jul 14 '16 at 18:40
  • Then: http://stackoverflow.com/a/18413058/2055998 – PM 77-1 Jul 14 '16 at 19:57

0 Answers0