使用JDK 1.7运行播放应用程序时出现UnsupportedClassVersionError

刚刚开始学习我的项目需求的Play框架,我的项目只build立在JDK 1.7上,所以我已经下载了Play 2.3.9版本,并通过键入activator new创build了一个示例项目。 然后移到示例项目目录并执行activator run 。 然后我看到JDK不兼容的exception。 我在哪里必须做出改变来处理这个问题?

日志:

 [info] Loading project definition from E:\workspace\play\first-app\project [info] Set current project to first-app (in build file:/E:/workspace/play/first-app/) java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:535) at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:535) at scala.Option.fold(Option.scala:157) at com.typesafe.sbt.web.SbtWeb$.com$typesafe$sbt$web$SbtWeb$$load(SbtWeb.scala:549) at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143) at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143) at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55) at sbt.Project$.setProject(Project.scala:319) at sbt.BuiltinCommands$.doLoadProject(Main.scala:484) at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475) at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60) at sbt.Command$.process(Command.scala:92) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98) at sbt.State$$anon$1.process(State.scala:184) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) at sbt.MainLoop$.next(MainLoop.scala:98) at sbt.MainLoop$.run(MainLoop.scala:91) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:70) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:65) at sbt.Using.apply(Using.scala:24) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:65) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:48) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:32) at sbt.MainLoop$.runLogged(MainLoop.scala:24) at sbt.StandardMain$.runManaged(Main.scala:53) at sbt.xMain.run(Main.scala:28) at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109) at xsbt.boot.Launch$.withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35) at xsbt.boot.Launch$.launch(Launch.scala:117) at xsbt.boot.Launch$.apply(Launch.scala:18) at xsbt.boot.Boot$.runImpl(Boot.scala:41) at xsbt.boot.Boot$.main(Boot.scala:17) at xsbt.boot.Boot.main(Boot.scala) [error] java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0 

52 = Java com.typesafe.config.ConfigException = Java 7 .. On com.typesafe.config.ConfigException ; 所以你有一个太新的图书馆。

说明:

  • Java SE 8 = 52
  • Java SE 7 = 51
  • Java SE 6.0 = 50

Java 8的主要版本是52,这意味着如果我们从Java 8安装中运行javac命令,它将默认生成一个主版本为52的类。但是,如果我们在JRE 7中运行类文件,我们将得到“Unsupported major.minor版本52.0“。

解答:

在%JAVA_HOME%中有一个错误的configuration

  • java -version java版本“1.8.0_45”

  • javac -version javac 1.8.0_45

  • @echo %JAVA_HOME% C:\ Program Files \ Java \ jdk1.7.0_75

设置临时path

  • set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45

  • @echo %JAVA_HOME% C:\ Program Files \ Java \ jdk1.8.0_45

发生ConfigException是因为从版本1.3.0开始,com.typesafe.config库只与JDK8兼容; 请参阅自述文件 。 您需要降级库版本。 使用

 "com.typesafe" % "config" % "1.2.1" 

尽pipe看起来我对java和javac使用了相同的版本:

  • java -version java版本“1.8.0_51”
  • javac -version javac 1.8.0_51

我的问题是(Linux Mint 17.1),我已经安装了oracle-java7oracle-java8所以必须有一个错误的configuration。

我卸载oracle-java7 ,一切工作正常。

面临类似的问题,通过更改版本解决

 //addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0") addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.9") 

以上更改exception得到解决(注:系统有Java 7)

有更高版本的例外:

 [info] Set current project to helloworld (in build file:/Users/suniltonger/Projects/play/helloworld/helloworld/) java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:559) at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:559) at scala.Option.fold(Option.scala:157) at com.typesafe.sbt.web.SbtWeb$.com$typesafe$sbt$web$SbtWeb$$load(SbtWeb.scala:573) at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143) at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143) at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55) at sbt.Project$.setProject(Project.scala:319) at sbt.BuiltinCommands$.doLoadProject(Main.scala:503) at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484) at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59) at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61) at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61) at sbt.Command$.process(Command.scala:93) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96) at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96) at sbt.State$$anon$1.process(State.scala:184) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96) at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96) at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) at sbt.MainLoop$.next(MainLoop.scala:96) at sbt.MainLoop$.run(MainLoop.scala:89) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68) at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63) at sbt.Using.apply(Using.scala:24) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30) at sbt.MainLoop$.runLogged(MainLoop.scala:22) at sbt.StandardMain$.runManaged(Main.scala:54) at sbt.xMain.run(Main.scala:29) at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109) at xsbt.boot.Launch$.withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35) at xsbt.boot.Launch$.launch(Launch.scala:117) at xsbt.boot.Launch$.apply(Launch.scala:18) at xsbt.boot.Boot$.runImpl(Boot.scala:41) at xsbt.boot.Boot$.main(Boot.scala:17) at xsbt.boot.Boot.main(Boot.scala) [error] java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0 [error] Use 'last' for the full log. [debug] > load-failed 

事实上@cib所说的解决了我的问题。 只要修改我的projet目录中的文件plugins.sbt

改行:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")

至:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.9")

而且你不会再犯activator run错误。