0

Have a Java project, which is setup to build a .jar file. Java 1.7 is installed, and have set the project to Language Level 6.
However, it keeps compiling the jar files (via the artifact builder) to Java 1.7, so I get the following error when trying to run on a Java 1.6 JVM:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mycompany/myproject/MyClass : Unsupported major.minor version 51.0
  • Under File -> Other Settings -> Default Settigns... -> Compiler, I've set "Project bytecode version" to 1.6,

  • Also tried setting "Additional command line parameters" to -target 1.6 and -source 1.6

  • Have also added this line to ~/.bash_profile (so that java -version returns 1.6.0_65) and restarting IntelliJ:

    export JAVA_HOME=/usr/libexec/java_home -v '1.6*'

But IntelliJ still keeps building the jar to Java 7, and it fails to run on JVM 1.6. What might I try next?

What is Project Language level in IntelliJ IDEA?

Community
  • 1
  • 1
prototype
  • 7,249
  • 15
  • 60
  • 94
  • Does your project maybe include some external libraries that are compiled for Java 7? – Henry Feb 09 '15 at 20:08
  • Awesome thought. Hadn't thought to check the other libraries. But somehow in checking your hypothesis the issue resolved itself silently! Mystery. thanks! – prototype Feb 09 '15 at 20:10
  • 2
    File | Other Settings | Default Settings... change the settings for new projects created in IntelliJ IDEA, not for the project you currently have open. To change the settings for the current project, go to IntelliJ IDEA | Preferences | Compiler. – yole Feb 09 '15 at 23:12
  • @yole, that's actually the answer. Trying repeatedly had found two routes to what seemed like the same thing. Mystery solved. – prototype Feb 10 '15 at 01:41

1 Answers1

1

You need to change the "Project bytecode version" setting under IntelliJ IDEA | Preferences | Compiler and not under File | Other Settings | Default Settings | Compiler.

yole
  • 92,896
  • 20
  • 260
  • 197