2

当我使用 mvn tomcat7:run log4j 工作正常但是当我使用 mvn tomcat7:deploy 在本地机器上的 tomcat 上运行时,我得到 log4j.properties 文件的 filenotfoundexception。有什么想法可以解决这个问题吗?

 <build>

    <plugins>

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <!--  --> <version>2.1</version> 

        <configuration>
            <url>http://localhost:8080/manager/text</url>
            <server>localhost</server>


        </configuration>
    </plugin>
</plugins>

更新

在 log4j.properties 中,我使用文件附加程序记录到一个名为“loging.log”的文件。该文件是在 tomcat/bin 目录中创建的,但它是空的。

4

2 回答 2

0

您的 log4j.properties 文件需要位于 src/test/resources 或 src/main/resources

于 2013-11-11T23:59:44.873 回答
0

从这里找到答案

不得不从

PropertyConfigurator.configure("log4j.properties");

对此

ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 
PropertyConfigurator.configure(classLoader.getResource("log4j.properties"));

另一种解决方案是硬编码 log4j.properties 文件的路径,但我不推荐它:

PropertyConfigurator.configure("C:/User/...../log4j.properties");
于 2013-11-11T11:49:44.017 回答