首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SBT在编译混合项目时给出“类文件有错误版本51.0,应该是49.0”吗?

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

Stack Overflow用户
提问于 2014-02-28 04:45:49
回答 1查看 2.9K关注 0票数 5

编辑:各种SBT选项

代码语言:javascript
复制
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项目时,我得到了以下错误,错误如下

代码语言:javascript
复制
[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

代码语言:javascript
复制
javac 1.7.0_51
javac: no source files
Usage: javac <options> <source files>
where possible options include:

java -version

代码语言:javascript
复制
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里

代码语言:javascript
复制
javaHome := Some(file("/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"))

强制java回家。SBT = 0.13.1

系统是Mac 10.9.2 (小牛)

EN

回答 1

Stack Overflow用户

发布于 2014-07-05 16:56:29

您不能使用javaHome设置来指定用于启动sbt的java版本,该版本只会指定哪些JDK将在其中查找,以及它在分叉时将使用哪些二进制文件。不幸的是,sbt的启动脚本不知道如何查看这个javaHome设置并更新自己。

您使用的是什么sbt脚本?您能添加一个which sbt输出并向我们展示这个脚本的内容吗?最有可能的情况是,该文件正在提取MacOSX原生JDK,而不是您已安装的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22086433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档