0

I have generated a jar using Maven and now i want to execute it from a batch file from a different directory. My jar has a few dependencies which are all dscribed in the pom file.[but are not in my jar] I was wondering is there a way to execute the jar without causing ClassNotFoundException? if i run the jar with the dependencies in it everything runs fine, but isn't it a bit wasteful to package all the external JARs in mine?

Tina
  • 13
  • 1
  • 6
  • possible dupplicate: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven – Jens Jul 28 '16 at 12:21
  • You can have the batch file set the classpath to include the dependencies.Note that (I think) if you do this, you can not use the `-jar` option with `java`. You'll have to set the main file explicitly. – bradimus Jul 28 '16 at 12:22
  • i know how to package my classes with all the dependencies in a JAR i dont know if its possiblr to run a jar without its dependencies – Tina Jul 28 '16 at 12:23
  • You need the dependencies, but they do not have to be packaged into your jar. – bradimus Jul 28 '16 at 12:25
  • @bradimus that's a way, thanks ;] – Tina Jul 28 '16 at 12:26

1 Answers1

2

Make the batch modify your classpath to add the needed jars to it.

Apassembler maven plugin may help.

Andres
  • 10,561
  • 4
  • 45
  • 63