我的 maven 项目的 pom.xml 如下所示:
<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>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
在 src/main/resources 目录中,我有一个名为 test.txt 的文件。在 src/main/java 目录中,我有一个包含以下行的类:
System.out.println(this.getClass().getResourceAsStream("test"));
当代码行在 Eclipse 中运行时,我得到输出
java.io.BufferedInputStream@1cd2e5f
当我将项目导出为 .jar 并运行它时,我得到了输出
null
我是不是配置错了什么?