I need to use tools.jar in my project, but it makes no sense to put it in a jar, since the user already has it. So, can it be used as a โdynamic dependencyโ? value, I want my code to compile using the tools.jar file found in my JAVA_HOME , but I do not want it to be packaged with it. I can add it to the classpath with double activation at runtime using the user JAVA_HOME . eg:
object Main1 extends App { val myjar = Main1.getClass.getProtectionDomain.getCodeSource.getLocation.getFile val tools = System.getProperty("java.home").dropRight(3)+"lib/tools.jar" // drop "jre" val arguments = Array("java", "-cp", myjar+":"+tools, "me.myapp.Main2") ++ args val p = Runtime.getRuntime.exec(arguments) p.getErrorStream.close p.getOutputStream.close }
FYI: I will package the application using the build plugin in a separate jar file.
EDIT:
an ugly solution would be to copy the tools.jar file to the lib directory in my project and add:
excludedJars in assembly <<= (fullClasspath in assembly) map { cp => cp filter {_.data.getName == "tools.jar"} }
in build.sbt can this be done more elegantly without copying the jar file? it would be much easier to switch the JVM and automatically use the "right" tools.jar file ...
source share