编译混合项目时SBT给出“类文件有错误版本51.0,应该是49.0”吗?

时间:2014-02-28 04:45:50

标签: scala sbt javac

编辑:各种SBT选项

show scalacOptions
List(-deprecation, -unchecked, -encoding, UTF-8, -Yinline-warnings, -feature)

show javaOptions
List()

about
[info] This is sbt 0.13.1
[info] The current project is {file:/Users/ThomasNorth/Documents/CODE/SERVER/MonetiseAlpha/monetise-webserver/}monetise-webserver 1.0.0-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info]
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3

尝试使用某些java源代码编译scala项目时出现以下错误,错误如下

[error] /Users/ThomasNorth/Documents/CODE/SERVER/MonetiseAlpha/monetise-webserver/src/main/java/com/boxbe/pub/email/EmailAddress.java:31: cannot access java.util.regex.Pattern
[error] bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/rt.jar(java/util/regex/Pattern.class)
[error] class file has wrong version 51.0, should be 49.0
[error] Please remove or make sure it appears in the correct subdirectory of the classpath.
[error] import java.util.regex.Pattern;
[error]                        ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] Total time: 13 s, completed 28/02/2014 3:36:38 PM

问题是,javac和java都更新到了最新版本

javac -version

javac 1.7.0_51
javac: no source files
Usage: javac <options> <source files>
where possible options include:

java -version

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

build.sbt

organization  := "com.monetise"

name := "webserver"

version := "1.0.0-SNAPSHOT"

scalaVersion := "2.10.3"

resolvers ++= Seq(
  Resolver.sonatypeRepo("release"),
  Resolver.sonatypeRepo("snapshots"),
  "Untyped" at "http://ivy.untyped.com/com.untyped/"
)

scalacOptions ++= Seq(
  "-deprecation",
  "-unchecked",
  "-encoding", "UTF-8",
  "-Yinline-warnings",
  "-feature"
  // "-Xcheckinit" // for debugging only, see https://github.com/paulp/scala-faq/wiki/Initialization-Order
  // "-optimise"   // this option will slow your build
)

我只安装了一个sdk,位于/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home

任何人都有任何想法为什么会这样?

我甚至试图把它放在我的globals.sbt

javaHome := Some(file("/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"))

强制java回家。 SBT是v 0.13.1

系统是Mac Osx 10.9.2(小牛队)

1 个答案:

答案 0 :(得分:0)

您无法使用javaHome设置指定用于启动 sbt的java版本,该版本仅指定将查找哪个JDK sbt,以及它将使用哪些二进制文件什么时候分叉。不幸的是,sbt的启动脚本不知道如何查看此javaHome设置并自行更新。

您使用的是哪个sbt脚本?您可以添加which sbt输出,并向我们显示此脚本的内容吗?很可能这个文件正在拉动MacOSX原生JDK而不是你已安装的JDK。