how to add tools.jar as a “dynamic dependency” in sbt. is it possible?

流过昼夜 提交于 2019-12-03 17:28:50

after reading more carefully the SBT Documentation, i found out how to do this:
in build.sbt i needed to add:

// adding the tools.jar to the unmanaged-jars seq
unmanagedJars in Compile ~= {uj => 
    Seq(Attributed.blank(file(System.getProperty("java.home").dropRight(3)+"lib/tools.jar"))) ++ uj
}

// exluding the tools.jar file from the build
excludedJars in assembly <<= (fullClasspath in assembly) map { cp => 
    cp filter {_.data.getName == "tools.jar"}
}

and that's about it... simple as that :)

There is an sbt plugin to do this for you now: https://github.com/chipsenkbeil/sbt-jdi-tools

I haven't tested this, but could you not use the % configuration syntax to only map the dependency into runtime or compile? surely tools.jar should be automatically included anyway?

libraryDependencies += "com.sun" % "tools" % "1.6.0" % system

I'm not sure about the "system" configuration, I know this works in maven, you could try this with "compile" instead though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!