设置 sbt 以使用 Java 7 进行编译? [英] Setting up sbt to use Java 7 for compilation?

查看:34
本文介绍了设置 sbt 以使用 Java 7 进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 compile 任务时遇到编译错误,因为源引用了 java.nio.file 包中仅出现在 Java 7 中的新类.

我在 build.sbt 中有以下内容:

javaHome := Some(file("/opt/jdk/jdk1.7.0"))叉 := 真

在 sbt 中:

<代码>>显示 java-home[信息] 一些(/opt/jdk/jdk1.7.0)

它在 Eclipse 中编译并运行良好.如何设置 sbt 以使用 Java 7 进行编译?

解决方案

目前最可靠(也许唯一)的方法是使用 JDK7 文件夹中的 java 启动 SBT.

修改你的 sbt 启动脚本;或使用 这个 允许您指定 Java Home(以及很多更多!)作为命令行选项.

~/code/scratch/20111009 sbt -java-home/Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home启动 sbt:使用 -help 调用其他选项[信息] 从/Users/jason/.sbt/plugins 加载全局插件[信息] 将当前项目设置为 default-3e990a(在构建文件中:/Users/jason/code/scratch/20111009/)>安慰[信息] 将 1 个 Scala 源编译到/Users/jason/code/scratch/20111009/target/scala-2.9.1/classes...[信息] 启动 Scala 解释器...[信息]欢迎使用 Scala 版本 2.9.1.final(OpenJDK 64 位服务器 VM,Java 1.7.0 内部).输入表达式以对它们进行评估.输入 :help 以获取更多信息.标度>java.util.Objects.equals(null, null)res0:布尔值 = 真

只需设置 javaHome := Some(file("/Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home")) 更改用于编译和 fork 进程的 Java 版本,但不会更改类路径上 Java 标准库的版本,也不会更改用于运行测试的版本,这些测试始终与 SBT 运行相同的 JVM.

I'm getting compile errors when running the compile task as the sources reference new classes in java.nio.file package that only appeared in Java 7.

I have the following in build.sbt:

javaHome := Some(file("/opt/jdk/jdk1.7.0"))

fork := true

In sbt:

> show java-home
[info] Some(/opt/jdk/jdk1.7.0)

It compiles and runs fine in Eclipse. How can I set up sbt to use Java 7 for compilation?

解决方案

The most reliable (perhaps only) way to do this at the moment it to start SBT with java in the JDK7 folder.

Modify your sbt launcher script; or use this one that allows you to specify Java Home (and so much more!) as command line options.

~/code/scratch/20111009 sbt -java-home /Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home
Starting sbt: invoke with -help for other options
[info] Loading global plugins from /Users/jason/.sbt/plugins
[info] Set current project to default-3e990a (in build file:/Users/jason/code/scratch/20111009/)
> console
[info] Compiling 1 Scala source to /Users/jason/code/scratch/20111009/target/scala-2.9.1/classes...
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.9.1.final (OpenJDK 64-Bit Server VM, Java 1.7.0-internal).
Type in expressions to have them evaluated.
Type :help for more information.

scala> java.util.Objects.equals(null, null)
res0: Boolean = true

Simply setting javaHome := Some(file("/Library/Java/JavaVirtualMachines/openjdk-1.7-x86_64/Contents/Home")) changes the Java version used to compile and fork processes, but does not change the version of the Java standard library on the classpath, nor the version used to run tests, which are always run the the same JVM as SBT.

这篇关于设置 sbt 以使用 Java 7 进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆