2014-02-28 43 views
5

編輯:各種SBT選項SBT在編譯混合項目時給出「類文件錯誤版本51.0,應該是49.0」?

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 

我正在試圖編譯Scala的項目,一些Java源時,下面的錯誤,錯誤是如下

[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的版本

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(小牛)

+2

「類文件錯誤版本51.0,應該是49.0」這意味着您在使用JDK 5中的類庫時使用JDK 5中的'javac'。請確保'JAVA_HOME'指向您的JDK 7安裝目錄。 – Jesper

+0

在終端中試過:「export JAVA_HOME ='/ usr/libexec/java_home -v 1.7'」來指定JAVA_HOME,但仍然得到同樣的錯誤。 – user2943976

+0

你的構建配置文件是怎麼樣的 - 'build.sbt'或'project/*。scala'文件?你使用任何?你可以在SBT控制檯上運行'show scalacOptions'和'show javaOptions'和'about'並將輸出添加到問題中? –

回答

0

您不能使用javaHome設置指定用於推出 SBT的Java版本,只會指定JDK sbt會查找它,以及它在fork時使用哪些二進制文件。不幸的是,sbt的啓動腳本不知道如何看待這個javaHome設置和更新自己。

什麼sbt腳本你使用?你可以添加一個which sbt輸出,並向我們展示這個腳本的內容?最有可能的這個文件正在拉動MacOSX本機JDK,而不是你安裝的那個。

相關問題