#Linux #Fedora #Java defaults and jasper reports compile issues

By | September 28, 2022

A common mistake is to set the alternatives just for java sdk.

This can lead to issues when several java versions are present.

Jasper Reports a well knows Java library used to generate ad-hoc pdf reports compiles the report templates and the temporary classes using the default system javac not the javac of the java version used by the application container under which the main application is running or the java version used to run the main application.

When using Jasper with a Jboss deployed application with Java 1.8, I was constantly getting the following exception when using a template blank_template.xml that was compiled by the Jasper Library.

java.lang.UnsupportedClassVersionError: blank_template_1664366684128_389835 has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at net.sf.jasperreports.engine.util.JRClassLoader.loadClass(JRClassLoader.java:338)

This basically tells us that a Java 1.8 (52) VM cannot load a class compiled with Java 11 (55).

Checking the alternatives for Java I had this:

❯ alternatives --config java

There are 5 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc35.x86_64-fastdebug/jre/bin/java)
   2           java-latest-openjdk.x86_64 (/usr/lib/jvm/java-18-openjdk-18.0.2.0.9-1.rolling.fc35.x86_64/bin/java)
 + 3           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc35.x86_64/jre/bin/java)
   4           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc35.x86_64-slowdebug/jre/bin/java)
*  5           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.fc35.x86_64/bin/java)

Enter to keep the current selection[+], or type selection number: 

root in ~ took 23s 
❯ alternatives --config javac

There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
   1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.345.b01-1.fc35.x86_64/bin/javac)
*+ 2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.16.1.1-1.fc35.x86_64/bin/javac)

Enter to keep the current selection[+], or type selection number: 

As you can see, the default java environment was set to java 1.8 but the default javac compiler which is used by the Jasper Library was set to java 11.

Changing the default javac to the java 1.8 fixes the issue.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.