簡體   English   中英

Eclipse 中 Maven 項目的類路徑 - src vs src/main/java

[英]Classpath for Maven project in Eclipse - src vs src/main/java

我正在嘗試將commons-logging.properties添加到要由commons-logging.1.1.3.jar獲取的類路徑中,默認情況下它使用 JDK14Logger,然后打印 DEBUG 日志。

當我在 /src 文件夾(一個普通的 Java 項目)下添加它時,它在 Run As -> Java Application 時被選中。

但是,對於 Maven 項目,我嘗試將此文件放置在項目根目錄下的“src/main/java”、“src/main/resources”的不同位置。 Run As -> Java Application 時不考慮它。

僅當通過如下所示的 VM 參數明確指定時,才會獲取日志配置文件:

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

Maven 項目的類路徑是什么?

我應該在哪里放置要提取的配置文件?

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

更新:

在此處輸入圖片說明

僅打印“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>

首先,確保為 Eclipse 安裝了 Maven 集成。 然后右鍵單擊您的apache-common-java-logging-root項目 > 配置 > 配置為 Maven 項目。

一旦您的項目啟用了 Maven,任何時候如果您認為 Eclipse IDE 與 Maven 設置不同,請右鍵單擊項目 > Maven > Update Project... > 勾選Update project configuration from pom.xml > OK

我的錯。 正如@mm759 所指出的,“src/main/resources”被選中。 由於日志記錄的工作方式,我感到很困惑。

"java.util.logging.config.file=" 應該作為 VM 參數出現或出現在 .properties 文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM