gpt4 book ai didi

java - Apache poi excel writer 在 ide 中工作但不在 fat jar 中工作? java.io.IOException : Your InputStream was neither an OLE2 stream, 也不是 OOXML str

转载 作者:行者123 更新时间:2023-12-04 20:08:53 24 4
gpt4 key购买 nike

代码在 IDE 中运行良好,但在普通 .jarfat .jar 中运行不正常?该程序在其他方面工作得很好。此外,non-fat .jar 也不起作用。

错误是:

Jun 08, 2021 11:43:14 AM DataManagers.ExcelWriter$WriterThread run
SEVERE: null
java.io.IOException: Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: OOXML, having providers: [org.apache.poi.hssf.usermodel.HSSFWorkbookFactory@405294c8]
at org.apache.poi.ss.usermodel.WorkbookFactory.wp(WorkbookFactory.java:300)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:199)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:163)
at DataManagers.ExcelWriter$WriterThread.run(ExcelWriter.java:61)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)

并且此错误重复 3 次。

我的 maven pom 是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Implementation</groupId>
<artifactId>Implementation</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

<groupId>org.openjfx</groupId>

<artifactId>javafx-controls</artifactId>

<version>11.0.2</version>

</dependency>
<dependency>
<groupId>com.github.mmarquee</groupId>
<artifactId>ui-automation</artifactId>
<version>0.4.3</version>
<type>jar</type>
</dependency>



<dependency> <!-- Excel -->
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.0.0</version>
</dependency> <!-- End of excel -->

<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.15.1
</version>
</dependency>

<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon-dom</artifactId>
<version>8.7</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>UserInterface.Main</mainClass>
</manifest>
</archive>

</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<excludes>
<exclude>**/UserInterface/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>

<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>-->


<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>UserInterface.Main</mainClass>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>UserInterface.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>Implementation</name>
</project>

部分代码示例:

FileInputStream f = new FileInputStream(file);
wb = WorkbookFactory.create(f);
s = wb.getSheet("Sheet1");
initialiseExcel();
f.close();
FileOutputStream fOut = new FileOutputStream(file);
initialiseExcel();
Row row = s.createRow(0);
Cell cell = row.createCell(1);
cell.setCellValue("Pvm"); wb.write(fOut);
fOut.close();
...

我搜索了修复程序,但似乎每个人都在说 fat jar 修复了它,但我正在运行 fat jar,但问题仍然出现,我真的不知道该怎么做?

非常感谢任何愿意提供帮助的人。

最佳答案

这是一个解决方案。服务加载器使用 META-INF/services 中的文件来获取已知的可用提供程序。当你构建你的 fat jar 时,来自 org.apache.poi:poiorg.apache.poi:poi-ooxml 的提供者文件没有​​合并,只有一个在你的 fat jar 子。一个简单的解决方案是在执行合并的 maven-shade-plugin 中添加一个内置转换器:

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

关于java - Apache poi excel writer 在 ide 中工作但不在 fat jar 中工作? java.io.IOException : Your InputStream was neither an OLE2 stream, 也不是 OOXML str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67884617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com