Punky
Punky

Reputation: 95

FileNotFound exception when trying to get File from resource

I cannot generate myJasperReports.jasper file because its throwing a FileNotFoundException while trying to read the file and create the report. I am using jasper-reports 3.7.5 and annotation-based Spring. Can someone tell what the problem might be?

In web.xml file:

<bean id="myReportTemplate" class="org.springframework.core.io.ClassPathResource">
    <constructor-arg value="mypackage/reports/jasper/template/SampleJasper.jasper"/>
</bean>

Thanks.

This is the stacktrace:

[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]

The Plugin I'm using in pom.xml file

<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>

Upvotes: 0

Views: 2289

Answers (1)

mprabhat
mprabhat

Reputation: 20323

The problem is that the SampleJasper.jasper file is not getting generated in specified folder, the folder itself is not created.

To generate Jasper Report you should call JasperCompileManager.compileReport() and you will pass the .jrxml file.

But in your case you have are specifying .jasper file which means you should have already compiled and placed the compile file in the location which you are providing in your application-context.xml.

If you are not precompiling it then you should specify the jrxml file for compilation, then compiled file you will location you will pass to the Jasper viewer.

Spring has documentation on jasper integration

Upvotes: 1

Related Questions