2016-09-18 69 views
-1

我想將commons-logging.properties添加到類路徑中,commons-logging.1.1.3.jar默認使用JDK14Logger,然後打印DEBUG日誌。Eclipse中Maven項目的類路徑 - src vs src/main/java

當我將其添加到/ src文件夾(一個普通的Java項目)下時,它被運行時 - > Java應用程序拾取。

但是,對於Maven項目,我嘗試將此文件放置在項目根目錄下的各個位置「src/main/java」,「src/main/resources」中。運行時 - > Java應用程序時未考慮它。

只有當通過VM參數,如以下明確指定的日誌配置文件被拾起:

-Djava.util.logging.config.file=C:\ws-learning\spring-tutorial-5\commons-logging.properties 

什麼是Maven項目類路徑?

我應該在哪裏放置配置文件?

爲什麼src /和src/main/java在類路徑方面表現不同?

UPDATE:

enter image description here

只有 「INFO」 級別的消息被打印。我不明白 「FINE」 級別的消息

handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler 
.level=SEVERE 
org.springframework.level=FINE 

java.util.logging.ConsoleHandler.level=ALL 

java.util.logging.FileHandler.level=FINE 

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter 
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 

更新2:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" output="target/classes" path="src/main/java"> 
     <attributes> 
      <attribute name="optional" value="true"/> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"> 
     <attributes> 
      <attribute name="optional" value="true"/> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> 
     <attributes> 
      <attribute name="maven.pomderived" value="true"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="output" path="target/classes"/> 
</classpath> 
+1

「src/main/resources」是應該在不知道commons-logging的情況下工作的路徑。 – mm759

+0

@ mm759請參閱我的更新。只打印「INFO」。如果它已經考慮了日誌配置文件,它應該打印出「FINE」級別的消息。 – user104309

+0

我不知道更新2中的文件類型,但排除內容看起來很奇怪。您可以右鍵單擊Eclipse中的項目並查看「構建路徑」。應包括「src/main/resources」。 – mm759

回答

0

我的壞。正如@ mm759指出的那樣,「src/main/resources」被選中。由於記錄工作的方式,我感到困惑。

「java.util.logging.config.file =」應作爲VM參數存在或存在於.properties文件中。

0

首先,確保你有Maven的集成安裝了Eclipse。然後右鍵點擊你的apache-common-java-logging-root項目>配置>配置爲Maven項目。

一旦你的項目使Maven的,在任何時候,如果你認爲Eclipse IDE已經從Maven的設置分歧,在項目右鍵單擊>Maven>Update Project...>勾選Update project configuration from pom.xml>OK