先写经验 :这类约定优于配置的思想,是为了方便大家更好得使用软件,大家不要作死非要自己去改路径。
问题的发现,是因为作死想自己去指定log4j的路径,绝对路径是没问题的,但是相对路径会报错。PropertyConfigurator.configure();最终也没法解决。在IDE或jar包中可以通过getClassLoader().getResource("log4j.properties");来获得存在于CLASSPATH中资源文件。
为了解决相对路径的问题,查阅了chasspath文件,并怀疑是excluding搞的鬼,但结果发现不是。
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
excluding="**" 的解释,中文基本找不到资料,最终找到比较合理的解释,是指使输出文件中,不要resource层级,而是直接文件显示。但是搞了2个小时,无法复现删除和不删除的区别。自己就这么理解,没去深究,因为本来就约定由于配置,你非要自己这么搞,钻牛角尖反而违反了本来使用工具的意义。
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
>
> Because of the excluding="**" statement the package explorer in Eclipse does
> not show the resources in the "flat package presentation" anymore.
> Rather the resources are shown in the "hierarchical package presentation".
> This is very annoying if you have a deep package structure with just a view resources.