所以我正在研究这个 JavaFx 应用程序(Java 8),它复制一个 .xlsx 文件并用 .txt 文件中的数据填充它,为此我使用 apache poi 依赖项。我已经通过 maven-assembly-plugin 成功构建了一个 fat jar。这是我的 pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>sample.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
我用以下方式构建它:
mvn clean compile assembly:single
当我在 IntelliJ 中运行 main.java 时,应用程序及其依赖项工作正常,当我通过 IntelliJ 运行它时,构建的 fat jar 启动并正常工作(执行所有功能没有问题)。
只有当我通过 cmd 文件(以启动 JavaFx 应用程序)在 IDE 之外启动我的 fat jar 时,我才会遇到问题。它启动并加载 .txt 文件就好了,但是在它应该使用依赖项并创建工作表的地方,程序什么也不做。这是我在 .cmd 文件中运行的内容:
start javaw -jar ExcelConverter-1.0-jar-with-dependencies.jar
我试过用各种其他插件(阴影等)构建它,似乎都有同样的问题。我也尝试过通过 intelliJ 作为工件来构建它,同样的问题。依赖顺序也不是问题,因为我只使用一个。