我必须在JasperReports的 JRXML 文件中导入一些自定义Java类。
我可以使用
<import value="org.ga.jasper.sample.MyCustomClass"/>
这工作得很好,我能够运行这个 jrxml 并测试我的代码。
当我想使用 jasperreports -maven-plugin将其预编译成 .jasper 文件时,问题就来了。
进行构建时,它抱怨说找不到我的包,因此导入无效。
package org.ga.jasper.sample does not exist
import org.ga.jasper.sample.MyCustomClass;
仅供参考,我的Java代码和.jrxml在同一个 Maven 模块中,但在不同的文件夹中。
以下是我的插件标签中的代码
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jasperreports-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>compile-reports</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <sourceDirectory>src/main/resources/jasper</sourceDirectory>
        <outputDirectory>${project.build.directory}/jasper</outputDirectory>
        <compiler>net.sf.jasperreports.engine.design.JRJavacCompiler</compiler>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>4.5.1</version>
        </dependency>
    </dependencies>
</plugin>