这件事终于搞定了看来问题部分在于理解 sbt 价值模型(及其对自定义运算符的纯粹过度使用!),部分在于了解 sbt 中使用的类型。
我将相应地编辑问题,但这是我的发现(和解决方案)。
sbt 价值观是预先考虑好的。它们不是我无法设置的变量myOwn
. The javaHome
是 sbt 的已知值(或者实际上是一个任务?)。
话虽如此,我想知道为什么 sbt 不能很好地找到适合我的 JDK。那好吧。
提示:使用val xxx: Nothing = expression
is a great查找各种事物类型的工具。一个人不能有一个类型的实例Nothing
这样总是会失败,并带有一个很好的错误消息,通知(未知)类型expression
.
我的来了javaHome
检测代码(来自build.sbt
):
//---
// Note: Wouldn't 'sbt' be able to provide us a nice default for this (the following logic
// would deserve to be automatic, not in a project build script). AK 4-Jan-2013
//
javaHome := {
var s = System.getenv("JAVA_HOME")
if (s==null) {
// tbd. try to detect JDK location on multiple platforms
//
// OS X: "/Library/Java/JavaVirtualMachines/jdk1.xxx.jdk/Contents/Home" with greatest id (i.e. "7.0_10")
//
s= "/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home"
}
//
val dir = new File(s)
if (!dir.exists) {
throw new RuntimeException( "No JDK found - try setting 'JAVA_HOME'." )
}
//
Some(dir) // 'sbt' 'javaHome' value is ': Option[java.io.File]'
}
这是使用它的代码片段(稍后在同一个文件中),确保我们可以访问jfxrt.jar
(JavaFX 2.x 运行时)。无论如何,Oracle(或 sbt)应该将其放在类路径上,因此所有这些都可以幸免。
//---
// JavaFX
//
// Note: We shouldn't even need to say this at all. Part of Java 7 RT (since 7u06) and should come from there (right)
// The downside is that now this also gets into the 'one-jar' .jar package (where it would not need to be,
// and takes 15MB of space - of the 17MB package!) AKa 1-Nov-2012
//
unmanagedJars in Compile <+= javaHome map { jh /*: Option[File]*/ =>
val dir: File = jh.getOrElse(null) // unSome
//
val jfxJar = new File(dir, "/jre/lib/jfxrt.jar")
if (!jfxJar.exists) {
throw new RuntimeException( "JavaFX not detected (needs Java runtime 7u06 or later): "+ jfxJar.getPath ) // '.getPath' = full filename
}
Attributed.blank(jfxJar)
}
请注意,sbt 不允许条目内有空行。为了避免这种情况,我使用了缩进//
我想要一些空白的行。