【发布时间】:2017-10-17 06:16:33
【问题描述】:
我尝试使用PropertyConfigurator.configure("log4j.properties") 方法为log4j 加载配置,但我一直遇到java.io.FileNotFoundException。
我关注this question 并将我的log4j.properties 文件放入resources 文件夹中。
我还像这样编辑了我的 pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}</targetPath>
<includes>
<include>log4j.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>src.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
因此,当我运行 mvn package 时,生成的目标文件夹并排包含我的 .jar 和 log4j.properties,但是当我运行我的 jar 时,我得到了找不到文件的异常。
我该如何解决这个问题?
【问题讨论】: