0

我无法生成 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>
4

1 回答 1

1

问题是 SampleJasper.jasper 文件没有在指​​定文件夹中生成,文件夹本身没有创建。

要生成 Jasper 报告,您应该调用JasperCompileManager.compileReport()并传递.jrxml文件。

但是在您的情况下,您正在指定.jasper文件,这意味着您应该已经编译并将编译文件放置在您在application-context.xml.

如果您没有预编译它,那么您应该指定要编译的 jrxml 文件,然后您将定位的编译文件将传递给 Jasper 查看器。

Spring 有关于jasper 集成的文档

于 2012-05-01T15:07:55.890 回答