2015-10-29 27 views
9

Wiem, że to pytanie było często zadawane, ale nie udało się znaleźć odpowiedniego rozwiązania. Podczas pracy zBłąd Parsowania Apache'a

XWPFDocument xdoc = new XWPFDocument(srcFile); 

lub

XSSFWorkbook workbook = new XSSFWorkbook(srcFile); 

I zawsze kończy się z powodu następującego błędu:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V from class org.apache.poi.openxml4j.opc.PackageRelationshipCollection 
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313) 
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163) 
    at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:131) 
    at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561) 
    at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:109) 
    at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:80) 
    at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:125) 
    at org.apache.poi.openxml4j.opc.ZipPackagePart.<init>(ZipPackagePart.java:78) 
    at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:243) 
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684) 
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275) 
    at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:266) 

Ludzie sugerowali, aby otworzyć PackageRelationshipCollection i ponowić próbę. Ale to nie pomogło wiele.

Również mam słoiki załadowany:

<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.13</version> 
    <type>jar</type> 
</dependency> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-scratchpad</artifactId> 
    <version>3.13</version> 
    <type>jar</type> 
</dependency> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-ooxml</artifactId> 
    <version>3.12</version> 
    <type>jar</type> 
</dependency> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-ooxml-schemas</artifactId> 
    <version>3.11</version> 
    <type>jar</type> 
</dependency> 

Odpowiedz

32

Z Apache POI FAQ:

Can I mix POI jars from different versions?

No. This is not supported.

All POI jars in use must come from the same version. A combination such as poi-3.11.jar and poi-ooxml-3.9.jar is not supported, and will fail to work in unpredictable ways.

Twój pom ma współzależności na słoikach Apache POI z 3,11, 3,12 i 3,13, co jak the FAQ explained isn't supported

Musisz zmienić te wszystkie na 3.13, wtedy zadziała

sugeruję coś takiego:

<properties> 
    <poi.version>3.13</poi.version> 
</properties> 
<dependencies> 
    <dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>${poi.version}</version> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-scratchpad</artifactId> 
    <version>${poi.version}</version> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-ooxml</artifactId> 
    <version>${poi.version}</version> 
    </dependency> 
    <!-- etc as needed --> 

W ten sposób można zapewnić wszystkie słoiki POI są z tej samej wersji!

+0

Dzięki za pomoc. To wystarczyło. – beingsuplab