java.io.StreamCorruptedException:无效的流标题:EFBFBDEF

时间:2014-06-06 09:44:46

标签: java maven jasper-reports subreport

我正在开发一个java web应用程序,我正在使用maven作为项目管理工具,现在我对这个问题感到疯狂。 我尝试从我的应用程序构建一个jasper报告,这个报告由我在src / main / resources中的许多子报告组成。 我尝试以下列方式加载这些子报表:

//Sub Report 1 
InputStream fileSubRep1=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport1.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep1));

//Sub Report 2 
InputStream fileSubRep2=(BufferedInputStream) getClass().getResourceAsStream("/fileSubReport2.jasper");
map.put("fileSubRep1",(JasperReport) JRLoader.loadObject(fileSubRep2));

问题是此方法 JRLoader.loadObject(fileSubRep1)的调用会产生以下异常:

        net.sf.jasperreports.engine.JRException: Error loading object from InputStream
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:248)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:228)
    at it.aiemonline.report.jasper.GeneraFattureServiceImpl.createMapFileJasper(GeneraFattureServiceImpl.java:292)
    at it.aiemonline.report.jasper.GeneraFattureServiceImpl.executeStreamByteFatturaPdf(GeneraFattureServiceImpl.java:890)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
    at it.aiemonline.utility.logger.SystemLogger.aroundExecuteLog(SystemLogger.java:187)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy78.executeStreamByteFatturaPdf(Unknown Source)
    at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel.visualizzaPdf(VisualizzaFatturaPanel.java:236)
    at it.aiemonline.vaadin.application.gui.fatturazione.visualizza.VisualizzaFatturaPanel$1.itemClick(VisualizzaFatturaPanel.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
    at com.vaadin.ui.Table.handleClickEvent(Table.java:3057)
    at com.vaadin.ui.Table.changeVariables(Table.java:2853)
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
    at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
    at org.eclipse.jetty.server.Server.handle(Server.java:346)
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1065)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:823)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220)
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at net.sf.jasperreports.engine.util.ContextClassLoaderObjectInputStream.<init>(ContextClassLoaderObjectInputStream.java:58)
    at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:243)
    ... 69 more

我在哪里做错了? 我该如何解决?

6 个答案:

答案 0 :(得分:35)

经过3天的头痛后,我解决了我的麻烦。我正在使用maven作为项目管理工具,我正在开发一个具有这种结构的模块化项目

|-- parent
   |-- model
    --pom.xml
   |-- services
    --pom.xml
   |-- web-app
    --pom.xml

问题是我尝试加载的文件像Input流一样位于服务模块的src / main / resources中,但是在web-app的pom.xml中我启用了资源过滤,并且从那个web-应用程序模块依赖于服务,在服务模块上扩展了过滤。

在maven网站Filtering的过滤部分中,我找到了:

警告:不要过滤包含图像等二进制内容的文件!这很可能会导致输出损坏。如果您同时拥有文本文件和二进制文件作为资源,则需要声明两个互斥的资源集。第一个资源集定义要过滤的文件,另一个资源集定义要不加改变的文件,如下所示:

然后我从我的网络应用程序模块中删除了以下代码,一切正常

<resources>
     <resource>
         <directory>src/main/resources</directory>
         <filtering>true</filtering>
    </resource>
</resources>

答案 1 :(得分:3)

感谢此解决方案@skizzo

一种不太激烈的方式,如果您仍然需要过滤其他一些文件,或者复制所有文件只是包含您需要过滤的所有文件(java,xml,properties ...)。

以下是我刚刚实施的解决方案,感谢您的帮助:

t

它根本没有相关性,我已经好几个小时了。它真的救了我的一天! ; - )

答案 2 :(得分:2)

我有完全相同的问题,我解决了在我的pom.xml中添加以下插件

{{ form_end(form, {'render_rest': false}) }}

答案 3 :(得分:1)

在我的情况下,我忘记从行尾修复ant任务中排除已编译的jasper报告。对我来说,下面的排除修复了问题:

<fixcrlf srcdir="${basedir}/target/etc"
    includes="**/*.*"
    excludes="**/*.jasper"
    eol="lf" eof="remove"/>

答案 4 :(得分:0)

对我来说,原因是Maven配置还不错。 生成报告时,我只是在输入错误名称的参数。

答案 5 :(得分:0)

就我而言,问题是Web应用程序上的JasperReport版本与.jasper文件不同。

大多数可能是用较新的版本编译的(外部,我认为是Tibco设计)。