Friday, February 4, 2011

Using Jasper templates inside a maven Java project

I have came across an issue with using compiled jasper templates inside a maven Java project. If I placed the jasper template inside the test resources for a project(src/test/resources) and then created a jasper report using that template in a test case everything worked smoothly. If however I moved the template in the project resources directory(src/main/java) and then tried to run the same test case I would get an

java.io.StreamCorruptedException:invalid stream header: EFBFBDEF exception.

It turns out this happens because I had the resources filtering enabled in my project and Maven filtered the jasper file, producing in the target folder a file that was different than what I had in my resource folder. Hence, the stream corrupted exception. The solution to solve this is to configure the maven resources plug-in to exclude the .jasper file from filtering like this:

<nonFilteredFileExtensions>
    <nonFilteredFileExtension>jasper</nonFilteredFileExtension> </nonFilteredFileExtensions>

9 comments: