2014-09-24 108 views
1

我在这个项目上使用Eclipse和Maven。在将代码打包到JAR文件中后,我需要将log4j.properties文件保留为可供更改,因此我无法将该文件放在src/main/resources中,如this post中所述。如何在Maven项目中更改log4j.properties的位置?

我发现this post说我可以添加参数给我的Java调用,但我真的想通过配置(当然,如果可能的话)这样做。

This reply到第一个提到的帖子是我能找到的最接近的解决方案。它显示了如何将属性文件与JAR包文件一起导出。

但是,当我将属性文件放在名为CONF的文件夹中时,我无法使其工作。任何人都可以告诉我做错了什么?在下面检查我的项目结构和我的pom.xml的一部分。

Project Structure http://oi62.tinypic.com/imuwxv.jpg

<build> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <targetPath>${basedir}/target</targetPath> 
      <includes> 
       <include>conf/log4j.properties</include> 
       <include>conf/configuracoes.properties</include> 
       <include>conf/aws.properties</include> 
      </includes> 
     </resource> 
    </resources> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.2</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.2</version> 
       <configuration> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
        <archive> 
         <manifest> 
          <mainClass>br.com.aplicacao.ProgramLauncher</mainClass> 
         </manifest> 
         <manifestEntries> 
          <Class-Path>./conf</Class-Path> 
         </manifestEntries> 
        </archive> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

回答

1

问题解决了。一些行在我的POM文件中丢失,直接在project树中。

<properties> 
    <log4j.configuration>conf/log4j.properties</log4j.configuration> 
</properties> 
0

在我的情况与./conf的设置没有与log4j的工作,但之后,我改变./conf/也没关系。

相关问题