我无法生成myJasperReports.jasper文件,因为它在试图读取文件和创建报告时抛出一个FileNotFoundException。我正在使用jasper-reports 3.7.5和基于注释的Spring。有人能说出问题的所在吗?
在web.xml文件中:
<bean id="myReportTemplate" class="org.springframework.core.io.ClassPathResource">
<constructor-arg value="mypackage/reports/jasper/template/SampleJasper.jasper"/>
</bean>谢谢。
这是堆栈跟踪:
[ERROR] java.io.FileNotFoundException: class path resource [mypackage/reports/jasper/template/SampleJasper.jasper] cannot be resolved to URL because it does not exist
[ERROR] at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:179)
[ERROR] at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48)
[ERROR] at mypackage/reports.ReportsServiceImpl.prepareChart(ReportsServiceImpl.java:93)
[ERROR]我在pom.xml文件中使用的插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
</plugin>发布于 2012-05-01 15:07:55
问题是没有在指定的文件夹中生成SampleJasper.jasper文件,也没有创建文件夹本身。
要生成Jasper报告,您应该调用JasperCompileManager.compileReport(),然后传递.jrxml文件。
但是在您的例子中,您指定了.jasper文件,这意味着您应该已经编译并将编译文件放置在您在application-context.xml中提供的位置。
如果没有预编译它,那么应该指定jrxml文件进行编译,然后将编译后的文件传递给Jasper查看器。
Spring有关于jasper积分的文档
https://stackoverflow.com/questions/10396682
复制相似问题