问题描述
因此,我正在研究此JavaFx应用程序(Java 8),该应用程序复制.xlsx文件并用.txt文件中的数据填充该文件,为此,我使用apache poi依赖项。我已经通过maven-assembly-plugin成功构建了一个胖子罐。这是我的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运行它时,内置的胖罐也将启动并正常运行(执行所有功能都没有问题)。
仅当我在IDE外部通过cmd文件(用于启动JavaFx应用程序)启动胖子时,才遇到问题。它会启动并正确加载.txt文件,但是在应该使用依赖项并创建工作表的时候,程序什么也不做。这是我在.cmd文件中运行的内容:
start javaw -jar ExcelConverter-1.0-jar-with-dependencies.jar
我尝试使用其他各种插件(阴影等)来构建它,似乎所有插件都存在相同的问题。 我也曾尝试通过intelliJ将其构建为工件,这是同样的问题。 依赖顺序也不是问题,因为我只使用一个。
解决方法
为此使用maven shade插件。检查http://maven.apache.org/plugins/maven-shade-plugin/index.html。
下面是示例
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
,
问题不是插件或依赖性不起作用,而是apache-poi依赖性过于占用内存,因此我的JVM内存不足。我安装的IntelliJ IDE默认情况下使用JVM 64位,而我的系统则使用32位版本。我能够将JVM更新到64位并使其正常工作。