First of all, sorry if this doubt is so easy. I'm a beginner in Java.
I'm trying to use a template of Microsoft Word document to create a dinamic report.
So I have a file TemplateGQ.docx, that I read using XWPFDocument doc = new XWPFDocument(OPCPackage.open("C:\\Lucas\\TemplateGQ.docx")); and after code some actions to replace specific values on it, I tryied to save this document in a new file.
To save it:
FileOutputStream out = new FileOutputStream(new File("C:\\fusion\\Java.docx"));
doc.write(out);
out.close();
After execute I get the error printed below.
I followed a lot of stack overflow questions and answers, but none of them solved my problem. The last one was that.
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : class org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream cannot be cast to class java.util.zip.ZipFile$ZipFileInputStream (org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @314ed053; java.util.zip.ZipFile$ZipFileInputStream is in module java.base of loader 'bootstrap')
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:602)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1557)
at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:248)
at com.neomind.fusion.custom.equiplex.controleMudanca.CreateReport2.start(CreateReport2.java:109)
at com.neomind.fusion.workflow.adapter.CustomActivityAdapter.start(CustomActivityAdapter.java:73)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.start(ActivityHandlerImpl.java:62)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy221.start(Unknown Source)
at com.neomind.fusion.workflow.ActivityJoinXor.conditionTriggeredImpl(ActivityJoinXor.java:32)
at com.neomind.fusion.workflow.ActivityJoin.conditionTriggered(ActivityJoin.java:161)
at com.neomind.fusion.workflow.ActivitySplit.triggerCondition(ActivitySplit.java:339)
at com.neomind.fusion.workflow.ActivitySplit.split(ActivitySplit.java:180)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.finish(ActivityHandlerImpl.java:174)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.finish(ActivityHandlerImpl.java:37)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy221.finish(Unknown Source)
at com.neomind.fusion.workflow.handler.TaskHandlerImpl.finish(TaskHandlerImpl.java:159)
at com.neomind.fusion.workflow.handler.TaskHandlerImpl.finish(TaskHandlerImpl.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy222.finish(Unknown Source)
at com.neomind.fusion.workflow.service.TaskServiceImpl.complete(TaskServiceImpl.java:340)
at com.neomind.fusion.workflow.service.TaskServiceImpl.complete(TaskServiceImpl.java:332)
at com.neomind.fusion.portal.portlets.workflow.TaskPortlet.doSend(TaskPortlet.java:519)
at com.neomind.fusion.portal.portlets.workflow.TaskPortlet.processAction(TaskPortlet.java:265)
at com.neomind.fusion.portal.PortalServlet.doGet(PortalServlet.java:225)
at com.neomind.fusion.portal.PortalServlet.doPost(PortalServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.security.license.filter.SecurityFilter.doFilter(SecurityFilter.java:136)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.ResourcesFilter.doFilter(ResourcesFilter.java:142)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.framework.base.resources.InitializeFilter.doFilter(InitializeFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.sso.filter.AuthenticationFilterChain.doFilter(AuthenticationFilterChain.java:33)
at com.neomind.sso.filter.impl.AuthenticationFilterImpl.doFilter(AuthenticationFilterImpl.java:90)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.MultipartFilter.doFilter(MultipartFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.PortalFilter.lambda$doFilter$0(PortalFilter.java:182)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3122)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3050)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3027)
at com.neomind.fusion.portal.PortalFilter.doFilter(PortalFilter.java:148)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
I added to the pom.xml this dependencies:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-dom</artifactId>
<version>1.8</version>
</dependency>
Thanks in advance