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

3

7

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]
Manisa answered 27/7, 2017 at 22:7 Comment(7)
Sounds related to this #23249831Correlative
Not sure this is the same issue because the answer in the question you referenced was that they were compiling with Java 1.8 and needed to compile with 1.7, but I already have my JDK in the intellij project set to 1.7.Manisa
What about the run configuration? Which Java version is specified there?Correlative
I don't see any option to set the Java version in the run config. Won't it use the JDK set in my project settings?Manisa
Not always as far as i know. Otherwise you wouldn't have a problem I supposeCorrelative
What version of Intellij do you use? Is that still compatible with JDK 7?Caryl
Question is duplicate! See stackoverflow.com/questions/10382929Complexioned
C
3

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")

Companionway answered 2/8, 2017 at 12:22 Comment(2)
IntelliJ doesn't give me that option when importing from existing sources. Also, there's no build.sbt in my project.Manisa
OP has noted that he is currently using java 7Capelin
D
1

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.

Demoniac answered 7/8, 2017 at 14:22 Comment(0)
S
0

Try to update Java version from version 1.7.0_80 to some newer 1.7 version (for example 1.7.0_131)

Spathic answered 2/8, 2017 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.