2016-09-18 74 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