我正在编写一个应用程序来将数据导出到Excel工作表.
我不会使用XSSFWorkbook类,因为我的Excel超过了HSSFWorkbook类的255列限制.
我下载了Apache POI库,并将下面的库包含在我的proyect中:
– poi-3.9.jar
– poi-excelant-3.9.jar
– poi-ooxml-3.9.jar
– poi-ooxml-schemas-3.9.jar
– poi-scratchpad-3.9.jar
– dom4j-1.6.1.jar
– stax-api-1.0.1.jar
– xmlbeans-2.3.0.jar
当我导出数据以获取Excel工作表时,我得到此运行时错误:
java.lang.ExceptionInInitializerError
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
Truncated. see log file for complete stacktrace
Caused By: java.lang.RuntimeException: Could not instantiate SchemaTypeSystemImpl (java.lang.reflect.InvocationTargetException): is the version of xbean.jar correct?
at schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.loadTypeSystem(Unknown Source)
at schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.<clinit>(Unknown Source)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.TypeSystemHolder.loadTypeSystem(Unknown Source)
Truncated. see log file for complete stacktrace
Caused By: org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sE130CAA0A01A7CDE5A2B4FEB8B311707/index.xsb (schemaorg_apache_xmlbeans.system.sE130CAA0A01A7CDE5A2B4FEB8B311707.index) - code 0
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1519)
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:273)
at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:185)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
Truncated. see log file for complete stacktrace
我在一篇文章中读到,因为xbean-xx.jar的版本,我注意到我没有这个库,我在我的项目中包含了xbean-2.3.jar版本,并没有改变任何东西.
我读了另一篇*其他解决方案的帖子:xmlbeans could not locate schema resource when repacking xml beans jar into my own jar.我不知道我是否正确理解了解决方案,但文件/schemaorg_apache_xmlbeans/system/sE130CAA0A01A7CDE5A2B4FEB8B311707/index.xsb位于jar poi-ooxml-schemas-3.9.jar中,所以我认为这不是我的问题.
有人可以帮我吗?谢谢.
解决方法:
我发现了你的问题
例外的关键是:
XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sE130CAA0A01A7CDE5A2B4FEB8B311707/index.xsb
接下来,我们看到你包含所有罐子的非标准方式(通常不推荐,包括出于这样的原因),我们看到这些线条:
<zipfileset src="../lib/poi-ooxml-3.10-FINAL-20140208.jar" includes="**/*.class, **/*.properties, **/*.txt" />
<zipfileset src="../lib/ooxml-schemas-1.1.jar" includes="**/*.class, **/*.properties" />
您明确只是提取某些类型的文件,并从这些文件中排除所有其他文件.查看异常中丢失文件的扩展名 – .xsb.查看您的显式包含列表.看看你错过了什么?
您应该重新访问构建罐子的整个方式以选择更“正常”的东西,或者确保实际包含您正在内联的罐子的所有相关部分,例如异常所述的.xsb文件