Скомпилируйте JasperReports jrxml с зависимостью от скриптлета в том же проекте через Maven

У меня есть проект отчета, который компилируется, упаковывается и включается в войну. Я использую плагин jasperreports-maven для компиляции шаблонов JasperReports в проекте отчета. У меня есть проблема с циклической зависимостью, когда для одного из шаблонов требуется класс скриптлета в том же проекте, но класс скриптлета не компилируется перед отчетами, и я получаю исключение ClassNotFound во время компиляции. Есть ли способ сначала скомпилировать класс перед шаблонами или каким-либо другим обходным путем, кроме объявления системной зависимости ранее скомпилированной версии jar?

Вот мой пом:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>report</artifactId>

<name>report</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>net.sf.jasperreports</groupId>
                                <artifactId>jasperreports-fonts</artifactId>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                            </artifactItem>
                            <artifactItem>
                                <groupId>net.sf.jasperreports</groupId>
                                <artifactId>jasperreports</artifactId>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                            </artifactItem>
                            <artifactItem>
                                <groupId>ar.com.fdvs</groupId>
                                <artifactId>DynamicJasper</artifactId>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jasperreports-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compile-reports</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>

                <outputDirectory>${project.build.directory}/generated-jasper</outputDirectory>
                <sourceDirectory>src/main/resources/com/example/report/</sourceDirectory>
                <compiler>net.sf.jasperreports.compilers.JRGroovyCompiler</compiler>
            </configuration>

            <dependencies>
                <dependency>
                    <groupId>net.sf.jasperreports</groupId>
                    <artifactId>jasperreports</artifactId>
                    <version>4.0.1</version>
                </dependency>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>1.8.5</version>
                </dependency>
                <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>1.2.16</version>
                </dependency>

                <!-- use this if you have a report dependency at compile time -->
                <!-- 
                <dependency>
                    <groupId>com.example.usedforcompilingjasperreports</groupId>
                    <artifactId>compilejasperreports</artifactId>
                    <scope>system</scope>
                    <version>0.0.1</version>
                    <systemPath>${basedir}/src/main/resources/com/example/report/lib/report-${version}.jar</systemPath>
                </dependency>
                -->
            </dependencies>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        org.codehaus.mojo
                                    </groupId>
                                    <artifactId>
                                        jasperreports-maven-plugin
                                    </artifactId>
                                    <versionRange>
                                        [1.0-beta-2,)
                                    </versionRange>
                                    <goals>
                                        <goal>compile-reports</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.0.6.RELEASE</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.0.6.RELEASE</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>persistence</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>ar.com.fdvs</groupId>
        <artifactId>DynamicJasper</artifactId>
        <version>3.1.9</version>
    </dependency>
    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>4.0.1</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports-fonts</artifactId>
        <version>4.0.1</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <!-- not used but necessary to avoid an unexpected compiletion exception 
            An exception has occurred in the compiler (1.6.0_04). Please file a bug at 
            the Java Developer Connection (http://java.sun.com/webapps/bugreport) after 
            checking the Bug Parade for duplicates. Include your program and the following 
            diagnostic in your report. Thank you. com.sun.tools.javac.code.Symbol$CompletionFailure: 
            class file for javax.persistence.CascadeType not found -->
        <groupId>org.hibernate</groupId>
        <artifactId>ejb3-persistence</artifactId>
        <version>1.0.1.GA</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>jfree</groupId>
        <artifactId>jfreechart</artifactId>
        <version>1.0.12</version>
    </dependency>
    <dependency>
        <groupId>jfree</groupId>
        <artifactId>jcommon</artifactId>
        <version>1.0.15</version>
    </dependency>
    <dependency>
        <groupId>com.force.api</groupId>
        <artifactId>force-wsc</artifactId>
        <version>22.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.sforce.soap</groupId>
        <artifactId>salesforce-webservices</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>
<parent>
    <groupId>com.example</groupId>
    <artifactId>assemble</artifactId>
    <version>2.2.0-SNAPSHOT</version>
    <relativePath>../assemble/pom.xml</relativePath>
</parent>
</project>

Спасибо,

Том

1 ответ

Решение

Это может быть немного поздно, но я думаю, что вы можете попытаться связать выполнение jasperreports-maven-plugin с более поздней фазой сборки maven.

По умолчанию он запускается на этапе создания ресурсов, когда классы Java еще не скомпилированы.

Проверьте абзац ниже поля кода на этой странице.

Другие вопросы по тегам