26

我知道有版本冲突。只是希望有人告诉我如何解决它。在以前的 stackoverflow 帖子中,没有人告诉解决方案。

版本: Ubuntu:12.04.1 LTS java:1.6.0_24(OpenJDK) javac:1.7.0_07(OpenJDK)

haider@haider-desktop:~/Documents/projects/java-projects/mytestapp$ play
[info] Loading project definition from /home/haider/Documents/projects/java-projects/mytestapp/project
[info] Set current project to mytestapp (in build file:/home/haider/Documents/projects/java-projects/mytestapp/)
       _            _ 
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/ 

play! 2.0.4, http://www.playframework.org

> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.

[mytestapp] $ run

--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on port 9000...

(Server started, use Ctrl+D to stop and go back to the console...)

[info] Compiling 5 Scala sources and 2 Java sources to /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/classes...
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes$javascript : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes$ref : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes$javascript : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/target/scala-2.9.1/src_managed/main/controllers/routes.java : java.lang.UnsupportedClassVersionError: controllers/routes$ref : Unsupported major.minor version 51.0
[warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: controllers/routes$javascript : Unsupported major.minor version 51.0
[warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: controllers/routes : Unsupported major.minor version 51.0
[warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: controllers/routes$ref : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/app/controllers/Application.java : java.lang.UnsupportedClassVersionError: controllers/Application$Hello : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/app/controllers/Application.java : java.lang.UnsupportedClassVersionError: controllers/Application : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/app/controllers/Application.java : java.lang.UnsupportedClassVersionError: controllers/Application$Hello : Unsupported major.minor version 51.0
[warn] Problem processing dependencies of source /home/haider/Documents/projects/libraries/play-2.0.4/samples/java/helloworld/app/controllers/Application.java : java.lang.UnsupportedClassVersionError: controllers/Application : Unsupported major.minor version 51.0
[warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: controllers/Application$Hello : Unsupported major.minor version 51.0
[warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: controllers/Application : Unsupported major.minor version 51.0
[info] play - Application started (Dev)
4

3 回答 3

27

您正在使用不同的 JDK 版本来编译和运行应用程序。你说:

java: 1.6.0_24 (OpenJDK) 
javac: 1.7.0_07 (OpenJDK)

所以你的编译器(javac)是一个比java命令更新的版本,这意味着第二个不能运行你的编译文件。您只能使用 1 个版本的 JDK(java 和 javac 相同)

于 2012-10-04T08:15:16.533 回答
23

在 Ubuntu 上更改 Java 版本以进行编译和运行,您需要调用:

sudo update-alternatives --config javac 

sudo update-alternatives --config java
于 2013-04-10T15:02:23.833 回答
5

更好的解决方案是更改目标版本,因此您可以像这样从 1.7 编译到 1.6: How can I set the javac compile version for Play Framework 2.0 to prevent "Unsupported major.minor version"?

把它放在你的 Build.scala 中:

val main = play.Project(appName, appVersion, appDependencies).settings(
  // Force compilation in java 1.6
  javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6")
)
于 2013-12-04T13:13:18.263 回答