cesarggf
cesarggf

Reputation: 41

Compile Jasper reports from Maven with ant task?

How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task? I tried using a maven plugin for compiling jasper reports files but it's still in beta, and it caused me many problems. I'd like to see the configuration in pom.xml.

Upvotes: 4

Views: 3814

Answers (3)

Vedran
Vedran

Reputation: 11029

Here's a complete example that solves problems with Eclipse m2e reporting errors with maven configuration, has reports neatly set in a separate folder and has classpath configured.

Just be sure to put your .jrxml files in src/main/jasperreports folder and you're set - every time you change the report, .jasper files will be regenerated.

pom.xml:

<properties>
    <jasperreports.version>5.0.0</jasperreports.version>
</properties>

<build>
    <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>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <sourceDirectory>src/main/java</sourceDirectory>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <!-- Include the generated reports in classpath -->
            <directory>target/jasper</directory>
        </resource>
        <resource>
            <!--Folder with .jrxml report files -->
            <directory>src/main/jasperreports</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jasperreports-maven-plugin</artifactId>
            <configuration>
                <!-- Folder where compiled reports will be generated -->
                <outputDirectory>${project.build.directory}/jasper</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile-reports</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jasperreports-maven-plugin</artifactId>
                    <version>1.0-beta-2</version>
                    <exclusions>
                        <exclusion>
                            <groupId>net.sf.jasperreports</groupId>
                            <artifactId>jasperreports</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>net.sf.jasperreports</groupId>
                    <artifactId>jasperreports</artifactId>
                    <version>${jasperreports.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.lowagie</groupId>
                    <artifactId>itext</artifactId>
                    <version>4.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
...

Upvotes: 1

cesarggf
cesarggf

Reputation: 1790

You can try jasperreports-maven-plugin, that way you don't have to use ant, Here is an example.

Upvotes: 1

Pascal Thivent
Pascal Thivent

Reputation: 570365

How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task?

You can use the custom Ant Tasks with the Maven AntRun Plugin. See the example provided in Using tasks not included in Ant's default jar.

Upvotes: 1

Related Questions