这是我的问题:我有一个使用 Swing 库的 Maven 项目,它是一个 GUI 应用程序,我想在我的 jar 文件中包含资源(图像和一个 config.properties 文件)。
这是我的pom.xml
代码:
<build>
<resources>
<resource>
<directory>${basedir}/resource</directory>
<includes>
<include>**/*.png</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>${basedir}/config</directory>
<includes>
<include>config.properties</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>.settings</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>bis.debug.mode.ui.MainBISDebugMode</mainClass>
</manifest>
</archive>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的项目结构:
我包含了在 pom.xml 中看到的目录和其中的文件,但仍然没有包含在 jar 文件中,并且在 GUI 应用程序上看不到图像。当我将程序作为 Java 应用程序运行时,一切都很好。
我的代码可能有问题吗?我该如何解决这个问题?
最佳答案
您只需将配置文件放入 src/main/resources
中,无需在 pom.xml
中添加资源,因为 src/main/resources
是maven的默认资源文件夹
关于java - 无法将资源添加到maven中的jar中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52072869/