How to run JasperReports with Java 8?

2

I can't compile tempaltes with JRJdtCompiler because jdtcore:3.1.0 does not support java 8.

Caused by: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files

I can't use JRJdk13Compiler, cause it can't compile templates which use functions.

  symbol:   method DATEFORMAT(Date,String)
  location: class report_1414506137290_237400
/Users/Mariusz/Work/coresuite-cloud/dataCloud/report_1414506137290_237400.java:255: error: cannot find symbol
                value = DATEFORMAT(((...

I know Java 8 is not yet supported, but is there some workaround? If not, is there some ETA? I wouldn't like to implement my own JRCompiler.

effingen's picture
Joined: Jul 10 2014 - 12:18am
Last seen: 1 month 2 weeks ago

1 Answer:

2

I tried simple update of eclipse jdt lirbary and it seems to be working.

            <dependency>
                <groupId>net.sf.jasperreports</groupId>
                <artifactId>jasperreports</artifactId>
                <version>5.6.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>eclipse</groupId>
                        <artifactId>jdtcore</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
 
            <dependency>
                <groupId>org.eclipse.jdt.core.compiler</groupId>
                <artifactId>ecj</artifactId>
                <version>4.4</version>
            </dependency>
effingen's picture
Joined: Jul 10 2014 - 12:18am
Last seen: 1 month 2 weeks ago

I'm getting the same problem with JDK8 and I'm trying to get your workaround going without success. Can you enumerate the step by step process you took, eg. what files you modified and what were the locations of these files.

msescott - 4 years 5 months ago

This is the only change I did. It was made in our main pom.xml file. We are using Maven.

effingen - 4 years 5 months ago

Here's what I did:
- I downloaded ecj-4.4.1.jar for the JDT core compiler
- I pointed my project's class path to include that jar and removed any reference to any other JDT core jar
- (I looked into jasper 5.6.1 but the jar file didn't have any pom.xml file so it must configure things differently, so I stayed with jasper 3.7.1.1)
- I got into jasperreports-3.7.1.1.jar then \META-INF\maven\jasperreports\jasperreports and edited the pom.xml within that folder with the following changes:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>3.7.1.1</version>
<exclusions>
<exclusion>
<groupId>eclipse</groupId>
<artifactId>jdtcore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>eclipse</groupId>
<artifactId>ecj</artifactId>
<version>4.4.1</version>
<scope>compile</scope>
</dependency>
- even after I rebuild and restart my project, I keep getting the following When my Java code calls: JasperCompileManager.compileReportToFile(JasperDesign p1, String p2);

org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:329)

msescott - 4 years 5 months ago
show 5 more...

It seems that you include Jasper library differently than I do. In my case Maven is doing all dependency resolving, and that is why I need to have pom.xml in the root directory of my project.

Are you using Maven? Or did you just downloaded Jasper and included it in your lib directly?

effingen - 4 years 5 months ago

The latter. Until now we have simply been using 2 jar files among all of our other jars in a lib folder. One is the Jasper Reports JAR and the other is a jar with the JDT core code. Prior to JDK8, everything worked by itself when loading/compiling Jasper jrxml files on the fly from Java code.

msescott - 4 years 5 months ago

It should be enough to update the ecj library then. Maybe try one version higher than the one which comes with Jasper.

effingen - 4 years 5 months ago

I have tried ecj-4.4.1.jar and jave also tried the old jdtcore 3.1.1 version.
Doesn't seem like any combination works.

msescott - 4 years 5 months ago

Thanks to effingen and having made changes to plugin as advised I was able to compile reports with Java 8.
Sorry, can not figure out how to format it nicely, anyway here it is

<!-- plugin to compile Jasper reports-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/templates/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/webapp/templates/</outputDirectory>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
<exclusions>
<exclusion>
<groupId>eclipse</groupId>
<artifactId>jdtcore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.4.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
</plugin>

slavaz - 3 years 2 months ago
Feedback