Sistema de blogs Diarium
Universidad de Salamanca
Pablo Gallardo's Blog
My professional web log about IT, Cybersecurity & Project Management
 

How to modify Java Compiler Version

 

Why would I need to change the Java compiler version?

We may tend to think that we should always use the latest version of the Java compiler.

However, if the compiler version is newer than the virtual machine version, system will trigger an error when trying to run. So we may want to modify Java compiler version be because of compatibility.

 

In my case, I have installed the latest JDK in a MacOS X computer and the latest JRE in other different Windows. To my surprise, there were version incompatibilities even when both were in the latest versions.

This was the error when double-clicking the JAR file:

Error: A JNI error has occurred, please check your installation and try again

Error: A JNI error has occurred, please check your installation and try again
When I ran the same JAR file using Windows Command Prompt, I got this error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: package/path/ProjectName has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0

When I am making a software, I expect that it is compatible on most computers without configuration changes. I consider more logical to modify my compiler version (even when it implies not using the latest version) rather than expecting all users to update their JRE’s and modify their configuration just to make run my application.

 

Correspondence between JDK and class file version

I had the clue that most computers were expecting class file version 52.0, but I was unsure what was the corresponding JDK version I had to use on my compiler. I had to make trial and error until I found the correspondence below.

 

JDK version / Class File Version

8 / 52

9 / 53

10 / 54

11 / 55

12 / 56

13 / 57

 

Modify compiler version for a project on NetBeans

You ccan modify the compiler version for a single project on NetBeans.

Right-click on project, go to Properties.

Go to “Sources”, then “Sources/Binary Format” and choose the corresponding JDK version (I had to).

NetBeans Sources Properties

 

pmgallardo

About pmgallardo

I studied Computer Science at University of Salamanca. Since then, I have been working first as developer and then as SAP consutant. This blog is about problems I dealt when using computers, and more important, the solutions I found. Whenever I am on an issue and suddenlly I have a flash that leads me to a solution, I document my discoveries in a post.

, , , , , , , , , ,

No comments yet.

Leave a Reply


*

Política de privacidad
Studii Salmantini. Campus de excelencia internacional