How can I set the javac compile version for Play F

2019-03-18 03:13发布

A module I am using must have been compiled with Java 1.7, and I only have 1.6.

If I want to for the module to be compiled for a specific version like 1.6, how can I set that in Play! Framework 2.0 so that I can prevent the "Unsupported major.minor version" errors.

In Play! 1.x you could set "java.version=1.6" in the application.conf.

I assume that in Play! 2.x it probably needs to be set somewhere for sbt - but where/how?

4条回答
我只想做你的唯一
2楼-- · 2019-03-18 03:27

In the file project/Build.scala, add the setting below if you want to compile with java 1.6 :

val main = play.Project(appName, appVersion, appDependencies).settings(
  // Force compilation in java 1.6
  javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6")
)
查看更多
小情绪 Triste *
3楼-- · 2019-03-18 03:34

I think the only solution is to create the file build.sbt in the root of the project and add

javaHome := Some(file("path_to_your_jdk"))

查看更多
孤傲高冷的网名
4楼-- · 2019-03-18 03:37

Adding

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

to the build.sbt file worked for me (to be transparent, in my case it was 1.7 to build with JDK 8).

查看更多
趁早两清
5楼-- · 2019-03-18 03:40

I figured this out, put

javaHome := Some(file("path_to_your_jdk"))

at the very end of your build.sbt file. Make sure your put it after "playJavaSettings" (if you have this line in your built.sbt).

Make sure you have the right path assigned to your sdk , you can verify this by typing :

java-home

in Play or activator console.

Also make sure you run

clean

in your console to get rid of all previously compiled resources.

now compile your code using

compile 

you should be good to go. I hope this helps!

查看更多
登录 后发表回答