我有一个Maven项目,其中包含一个主要项目的依赖项。其中一个依赖项将log4j.xml文件插入到从构建派生的最终jar中。我从项目中删除了所有重复的依赖项并手动插入log4j(不是从任何其他依赖项派生的)。但它还没有工作,另一个log4j文件仍在导入 我想知道如何停止导入这个log4j.xml文件,只从次要项目的src / main / resources获取log4j。
我在资源中只有一个log4j.xml而没有其他配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- Log4j Configuration -->
<!-- Created by Ant. Base file: log4j.xml.unparsed -->
<!-- ===================================================================== -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A size based rolling appender -->
<appender name="FILEZEUS" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="log/Generate_Curve.log" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="20" />
<param name="Append" value="true" />
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/> -->
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n" />
</layout>
</appender>
<logger name="org.apache">
<level value="WARN" />
</logger>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILEZEUS" />
</root>
</log4j:configuration>
答案 0 :(得分:-2)
问题仍然不明确但如果您想从资源加载任何文件,那么此代码将对您有所帮助。
import java.io.InputStream;
public final class ResourceLoader {
public static InputStream load(String fileName){
InputStream input = ResourceLoader.class.getResourceAsStream(fileName);
if(input==null){
input = ResourceLoader.class.getResourceAsStream("/"+fileName);
}
return input;
}
}