gpt4 book ai didi

scala - SBT 在编译混合项目时给出 "class file has wrong version 51.0, should be 49.0"?

转载 作者:行者123 更新时间:2023-12-03 17:50:50 25 4
gpt4 key购买 nike

编辑:各种 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 -版本
javac 1.7.0_51
javac: no source files
Usage: javac <options> <source files>
where possible options include:

版本
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 home。 SBT 是 v 0.13.1

系统是 Mac Osx 10.9.2 (Mavericks)

最佳答案

您不能使用 javaHome设置用于指定用于启动 sbt 的 java 版本,这将仅指定将查找哪个 JDK sbt,以及它在 fork 时将使用哪些二进制文件。可惜sbt的启动脚本不知道怎么看这个javaHome设置和更新自己。

什么 sbt你在使用脚本吗?你能添加一个 which sbt输出,并向我们展示这个脚本的内容?这个文件很可能是拉取 MacOSX native JDK 而不是您安装的那个。

关于scala - SBT 在编译混合项目时给出 "class file has wrong version 51.0, should be 49.0"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22086433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com