天天看點

maven插件編譯iReport源檔案

以下代碼實作,maven編譯打包後将.jrxml檔案編譯成.jasper檔案.

在pom.xml中進行配置

<dependencies>
	<dependency>
		<groupId>net.sf.jasperreports</groupId>
		<artifactId>jasperreports</artifactId>
		<version>3.7.0</version>
	</dependency>
</dependencies>

<!--不打包jrxml檔案-->
<build>
	<resources>
		<resource>
			<directory>src/main/resources</directory>
			<filtering>true</filtering>
			<excludes>
				<exclude>**/*.jrxml</exclude>
			</excludes>
		</resource>
	</resources>
	<plugins>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>jasperreports-maven-plugin</artifactId>
			<configuration>
				<sourceDirectory>src/main/resources</sourceDirectory>
				<outputDirectory>target/classes</outputDirectory>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>compile-reports</goal>
					</goals>
				</execution>
			</executions>
			<dependencies>
				<dependency>
					<groupId>net.sf.jasperreports</groupId>
					<artifactId>jasperreports</artifactId>
					<version>3.7.0</version>
				</dependency>
			</dependencies>
		</plugin>
	......
	</plugins>
</build>
           

 需要注意的是,java類中對jasper檔案進行解析的jar包版本需要和pom.xml檔案中的版本一緻。