使用Maven Exec插件时应该在哪里找到log4j.properties?

Arm*_*and 7 configuration maven-2 log4j

我试图在我正在使用exec-maven-plugin执行的项目中使用log4j.我尝试将文件放在以下位置:

$PROJECT_HOME
$PROJECT_HOME/src/main/resources
$PROJECT_HOME/target
$PROJECT_HOME/target/classes
Run Code Online (Sandbox Code Playgroud)

对于文件的所有位置,我在执行代码时收到以下消息:

log4j:WARN No appenders could be found for logger (mypacakge.MyClass).
log4j:WARN Please initialize the log4j system properly.
Run Code Online (Sandbox Code Playgroud)

log4j.properties文件应该放在哪里?


exec-maven-plugin配置:

...
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version>
    <configuration>
        <mainClass>mypackage.Main</mainClass>
    </configuration>
</plugin>
...
Run Code Online (Sandbox Code Playgroud)

Jea*_*evy 0

我不确定这是正确的方法(因为我不知道这个插件),但您可以使用插件的配置来向虚拟机的类路径指定文件的正确位置:

<configuration>
   <executable>maven</executable>
   <!-- optional -->
   <workingDirectory>/tmp</workingDirectory>
   <arguments>
       <argument>-classpath</argument>
       <argument>/path/to/dirthatcontainslog4J</argument>
      ...
   </arguments>
</configuration>
Run Code Online (Sandbox Code Playgroud)

使用这样的插件的目的是什么?如果这是为了测试您的应用程序,您可能应该使用 maven-dependency-plugin :http://www.sonatype.com/books/mvnex-book/reference/customizing-sect-custom-packaged.html

您可以在这里找到更多信息: maven jar-with-dependencies log4j

如何使用 Maven 创建具有依赖项的可执行 JAR?

问候