How do I run a Play Framework 2.1 project in IntelliJ?

I have an existing Play 2.1 project. I've been running it with the console and it works fine. However, when I try to run it with IntelliJ using these instructions it doesn't work:

https://www.jetbrains.com/help/idea/getting-started-with-play-2-x.html#run_debug_playApp

First I tried just running it by right clicking on the app and selecting "run play 2 app". It would not run and it gave me this error:

sbt.IncompatiblePluginsException: Binary incompatibility in plugins detected.

After some research into the issue I added -Djline.terminal= to my JVM options and tried again. This time it ran, but gave this error when I tried to open a page in the browser:

Global : Unsupported major.minor version 52.0

Finally, I tried reimporting my project into intellij. Before it would import, it forced me to update my SBT version in build.properties from 0.12.2 to 0.12.4. I did this, but still getting the same errors listed above.

NOTE: I have Java 7 set as my JDK.

Here is the full stack trace:

play.api.PlayException: Cannot init the Global object[Global : Unsupported major.minor version 52.0]
    at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:57) ~[play_2.10-2.1.1.jar:2.1.1]
    at play.api.WithDefaultGlobal$$anonfun$play$api$WithDefaultGlobal$$globalInstance$1.apply(Application.scala:51) ~[play_2.10-2.1.1.jar:2.1.1]
    at play.utils.Threads$.withContextClassLoader(Threads.scala:18) ~[play_2.10-2.1.1.jar:2.1.1]
    at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$globalInstance(Application.scala:50) ~[play_2.10-2.1.1.jar:2.1.1]
    at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance$lzycompute(Application.scala:383) ~[play_2.10-2.1.1.jar:2.1.1]
    at play.api.DefaultApplication.play$api$WithDefaultGlobal$$globalInstance(Application.scala:383) ~[play_2.10-2.1.1.jar:2.1.1]
Caused by: java.lang.UnsupportedClassVersionError: Global : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.7.0_80]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) ~[na:1.7.0_80]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.7.0_80]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) ~[na:1.7.0_80]
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71) ~[na:1.7.0_80]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.7.0_80]

The issue is because of Java version mismatch. Referring to the Wikipedia Java Class Reference :

J2SE 8 = 52

J2SE 7 = 51

When importing project try to change project SDK from Java 8 to Java 7

You can try adding the following to your build.sbt:

javacOptions ++= Seq("-source", "1.7", "-target", "1.7")


Global : Unsupported major.minor version 52.0

This means that you have compiled with JDK 1.8 and try to run in JDK 1.7. The issue is because of Java version mismatch. (Check this detail example)

Below are the list of reported major numbers Source Wiki:

Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

Solution

Possible solution is make-sure class compilation of the project happens in Java 1.7 instead of Java 1.8. Do the following step to solve it (Compile the code using the -target 1.7 option) :

In conf/application.conf , make sure java.source=1.7 is set.


尝试将Java版本从1.7.0_80更新到更新的1.7版本(例如1.7.0_131)

链接地址: http://www.djcxy.com/p/96976.html

上一篇: 通过终端获取用于mac代理变量的Docker

下一篇: 如何在IntelliJ中运行Play Framework 2.1项目?