阅读使用Apache POI .xlsx文件给org.apache.poi.POIXMLException Linux机器 [英] Reading .xlsx file using apache poi gives org.apache.poi.POIXMLException on linux machine
问题描述
我有一个应用程序,它读取.xlsx文件并显示该内容给用户。该应用程序工作正常的Windows环境。
我这个部署Web应用程序上的tomcat6 .war文件Ubuntu的服务器上。我也复制了的.xlsx文件的服务器上。
在code中的文件的路径是正确的。
但线
的FileInputStream文件=新的FileInputStream(新文件(文件名));
XSSFWorkbook工作簿=新XSSFWorkbook(文件);
给出了一个错误
java.lang.reflect.InvocationTargetException
org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
org.apache.poi.xssf.usermodel.XSSFWorkbook<&初始化GT;(XSSFWorkbook.java:207)
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107)
我已签了变量文件名中包含的文件服务器上的正确路径和文件名(/usr/local/Metrics/MetricFiles/FY2013_Q2_GIT_Review_Metrics_by_LSS-GC.xlsx)
由于ubunut服务器是虚拟机,我已经复制使用WinSCP赋予的文件的.xlsx。文件的大小也是正确的。
为什么发生在Linux平台上这个错误?
添加其他异常痕迹
产生的原因:java.lang.reflect.InvocationTargetException在
sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)的
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)在
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)在
java.lang.reflect.Constructor.newInstance(Constructor.java:525)在
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)... 68更多
在java.lang.String中在java.util.Arrays.copyOfRange(Arrays.java:2694)Java堆空间<&初始化GT;(String.java:203)为:java.lang.OutOfMemoryError:所致。
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseCdataLiteral(PiccoloLexer.java:3027)在
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseQuotedTagValue(PiccoloLexer.java:2936)在
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseAttributesNS(PiccoloLexer.java:1754)在
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(PiccoloLexer.java:1521)在
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(PiccoloLexer.java:1362)在
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:4678)在
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290)在
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400)在
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714)在
org.apache.xmlbeans.impl.store.Locale $ SaxLoader.load(Locale.java:3439)在
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1270)在
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1257)在
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)在
org.openxmlformats.schemas.s preadsheetml.x2006.main.StyleSheetDocument $ Factory.parse(来源不明)在
org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121)在
org.apache.poi.xssf.model.StylesTable<&初始化GT;(StylesTable.java:92)在
sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)的
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)在
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)在
java.lang.reflect.Constructor.newInstance(Constructor.java:525)在
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)在
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)在
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)在
org.apache.poi.xssf.usermodel.XSSFWorkbook<&初始化GT;(XSSFWorkbook.java:207)在
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107)在
sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)的
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在
java.lang.reflect.Method.invoke(Method.java:601)在com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
推动评论一个答案......
您的堆栈跟踪,这解释了什么是打破和关键部分原因是:
产生的原因:java.lang.OutOfMemoryError:Java堆空间
java.util.Arrays.copyOfRange(Arrays.java:2694)
这是告诉我们的Java并没有分配给它足够的内存来存储所有的处理文件限嗣继承
数据如果你需要增加你的JVM堆大小的帮助,我会建议您查看此previous问题或这个,这既谈你经历了这一切。
I have an application which reads an .xlsx file and displays the content to the user. The application works fine on a windows environment.
I deployed the .war file of this web app on tomcat6 on a ubuntu server. I also copied the .xlsx files on the server.
The path of the files in the code is correct.
But the line
FileInputStream file = new FileInputStream(new File(FileName));
XSSFWorkbook workbook = new XSSFWorkbook(file);
gives an error
java.lang.reflect.InvocationTargetException
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107)
I have checked that the variable FileName contains the correct path and filename of the files on server(/usr/local/Metrics/MetricFiles/FY2013_Q2_GIT_Review_Metrics_by_LSS-GC.xlsx)
Since the ubunut server is a VM, I had copied the .xlsx files using WinSCP. The size of the files is also correct.
Why is this error occurring on linux platform?
Adding the Additional exception trace
Caused by: java.lang.reflect.InvocationTargetException at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at
java.lang.reflect.Constructor.newInstance(Constructor.java:525) at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) ... 68 more
Caused by: java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:2694) at java.lang.String.<init>(String.java:203) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseCdataLiteral(PiccoloLexer.java:3027) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseQuotedTagValue(PiccoloLexer.java:2936) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseAttributesNS(PiccoloLexer.java:1754) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseOpenTagNS(PiccoloLexer.java:1521) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.parseTagNS(PiccoloLexer.java:1362) at
org.apache.xmlbeans.impl.piccolo.xml.PiccoloLexer.yylex(PiccoloLexer.java:4678) at
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yylex(Piccolo.java:1290) at
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.yyparse(Piccolo.java:1400) at
org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:714) at
org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3439) at
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1270) at
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1257) at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345) at
org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source) at
org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121) at
org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:92) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at
java.lang.reflect.Constructor.newInstance(Constructor.java:525) at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60) at
org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403) at
org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155) at
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207) at
com.qm.action.GetProjectNames.execute(GetProjectNames.java:107) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at
java.lang.reflect.Method.invoke(Method.java:601) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
Promoting a comment to an answer...
The key part of your stacktrace, which explains what has broken and why, is:
Caused by: java.lang.OutOfMemoryError: Java heap space at
java.util.Arrays.copyOfRange(Arrays.java:2694)
This is telling us that Java didn't have enough memory allocated to it to store all of the data that processing your file entails
If you need help with increasing your JVM heap size, I would suggest you review this previous question or this one, which both talk you through it all.
这篇关于阅读使用Apache POI .xlsx文件给org.apache.poi.POIXMLException Linux机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!