问题
在IDEA中,第在src/main路径下添加了xml,使用如下代码加载xml文件时:
String path = JsoupDemo.class.getClassLoader().getResource("test.xml").getPath();
报错:Exception in thread "main" java.lang.NullPointerException at xml.Jsoup.Jsoup,根据错误信息判断是由于没有成功加载xml文件所致。
解决方案
参考:https://blog.youkuaiyun.com/zhoucheng05_13/article/details/78072410
配置maven中的pom文件,在pom文件中增加如下配置:
<build>
<resources>
<resource>
<directory>src/main</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>