Jasper Reports w/Maven - Как указать версию Java для компиляции?
Можно ли указать, какую версию Java использовать при компиляции файлов .jrxml с отчетами Jasper в Maven (используя jasperreports-maven-plugin)? Я видел этот пост в блоге, утверждая, что Jasper использует "виртуальную машину по умолчанию на вашем компьютере", а не "ту же версию maven-compiler-plugin". Если я не могу изменить или гарантировать переменную окружения JAVA_HOME, как я могу заставить Jasper компилироваться с Java6?
Вот фрагмент из моего 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>
Глядя на Документы Codehaus, вы можете использовать параметр, но он не говорит, как указать, какую версию Java.
Спасибо!
Ответы
Ответ 1
В соответствии с этой проблемой следующие параметры могут помочь вам:
<configuration>
...
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler>
...
</configuration>
1.0-beta-2, однако, не обладает этими свойствами, поэтому необходима более поздняя версия. Вы можете использовать версию плагина моментального снимка от здесь, самостоятельно создать плагин из исходного кода. Насколько я могу судить, код плагина из магистрали поддерживает эти параметры.
Ответ 2
Мне пришлось сделать несколько дополнительных настроек:
- установить eclipse: jdtcore как исключение в 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>
- установить
org.eclipse.jdt.core.compiler:ecj
как зависимость плагина;
JasperReports-Maven-плагин:
<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>
Примечание: порядок зависимостей плагина jasperreports-maven-plugin
был актуален для меня (не спрашивайте меня, почему).