2017-05-17 10 views
0

PropertyConfigurator.configure("log4j.properties")メソッドを使用してlog4jの設定をロードしようとしましたが、私はjava.io.FileNotFoundExceptionのままです。Mavenリソースフォルダを使用してLog4j.propertiesが見つかりません

私は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ファイルを実行したときに私が取得しますファイルが見つかりませんでした例外。

この問題を解決するにはどうすればよいですか?

答えて

0

注: してください、誰かがあなたのジャーに依存されている場合、誤って自分のロギングを無効にすることができる、それがクラスパスに複数のlog4j.propertiesファイルの原因となります、最後のJarファイルにlog4j.propertiesを含んでいませんどのJarが最初にロードされるかによって異なります。

関連する問題