Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasper Reports w/ Maven - How do I specify Java version to compile with?

Is there any way I can specify which version of Java to use when compiling my .jrxml files with Jasper Reports in Maven (using jasperreports-maven-plugin)? I saw this blog post saying claiming that Jasper uses the "default virtual machine set in your computer" and not "same version of the maven-compiler-plugin". If I cannot change or guarantee the JAVA_HOME environment variable, how can I get Jasper to compile with Java6?

Here is a snippet from my pom.xml:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jasperreports-maven-plugin</artifactId>
        <version>1.0-beta-2</version>
        <configuration>
            <outputDirectory>${project.build.directory}/classes</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>5.0.1</version>
            </dependency>
        </dependencies>
    </plugin>
    <plugin>
</plugins>

Looking on the Codehaus docs, there is a parameter you can use, but it doesn't say how to specify which Java version.

Thanks!

like image 567
rsteier Avatar asked Oct 25 '13 22:10

rsteier


People also ask

How do I compile a Jrxml file?

Expand this group, find your . jrxml report and rightclick on it. In context menu choose 'Compile report'. Then you get compiled .

What is Jasper in Java used for?

JasperReports is an open source Java reporting tool that can write to a variety of targets, such as: screen, a printer, into PDF, HTML, Microsoft Excel, RTF, ODT, comma-separated values (CSV) or XML files.


1 Answers

I had to make some additional configurations:

  • set eclipse:jdtcore as exclusion in jasperresports;
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>5.6.0</version>
    <exclusions>
        <exclusion>
        <groupId>eclipse</groupId>
        <artifactId>jdtcore</artifactId>
    </exclusion>
    </exclusions>
</dependency>
  • set org.eclipse.jdt.core.compiler:ecj as plugin dependency;

jasperreports-maven-plugin:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jasperreports-maven-plugin</artifactId>
                <version>1.0-beta-4-OPENNMS-20160912-1</version>
                <configuration>
                    <outputDirectory>src/main/webapp/WEB-INF/reports</outputDirectory>
                    <maven.compiler.source>${compileSource}</maven.compiler.source>
                    <maven.compiler.target>${compileSource}</maven.compiler.target>
                    <compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile-reports</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.eclipse.jdt.core.compiler</groupId>
                        <artifactId>ecj</artifactId>
                        <version>4.4.1</version>
                    </dependency>
                    <dependency>
                        <groupId>net.sf.jasperreports</groupId>
                        <artifactId>jasperreports</artifactId>
                        <version>5.6.0</version>
                    </dependency>
                    <dependency>
                        <groupId>net.sf.barcode4j</groupId>
                        <artifactId>barcode4j</artifactId>
                        <version>2.0</version>
                    </dependency>
                </dependencies>

Note: the dependencies order of plugin jasperreports-maven-plugin was relevant for me (don't ask me why).

like image 154
Renato Rodrigues Avatar answered Sep 16 '22 14:09

Renato Rodrigues