-1

I am trying to add commons-logging.properties to the classpath to be picked up by commons-logging.1.1.3.jar which uses JDK14Logger by default and then print DEBUG logs.

When I added this under /src folder (a normal Java project),it was picked up when Run As -> Java Application.

However, for a Maven project,I tried placing this file at various places "src/main/java", "src/main/resources", under the root of the project. It wasn't considered when Run As -> Java Application.

Only when explicitly specified through a VM argument like the following, the log config file was picked up:

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

What is a classpath for a maven project?

Where should I place the config file to be picked up?

Why src/ and src/main/java behaves differently with respect to classpath?

UPDATE:

enter image description here

Only "INFO" level messages are printed. I don't see "FINE" level messages

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

UPDATE 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>
user104309
  • 690
  • 9
  • 20
  • 1
    "src/main/resources" is the path that should work without knowing commons-logging much. – mm759 Sep 18 '16 at 15:43
  • @mm759 Please see my update. Only "INFO" are printed. If it has considered the log config file, it should have printed the "FINE" level messages. – user104309 Sep 18 '16 at 16:06
  • I don't know the kind of file in Update 2, but the excludes look strange. You can right-click on the project in Eclipse and have a look at the "Build Path". "src/main/resources" should be included. – mm759 Sep 18 '16 at 19:46

2 Answers2

0

First, make sure you have Maven integration for Eclipse installed. Then right-click on your apache-common-java-logging-root project > Configure > Configure as Maven project.

Once your project has Maven enabled, at any time if you think Eclipse IDE has diverged from the Maven settings, right-click on project > Maven > Update Project... > Tick Update project configuration from pom.xml > OK

Mickael
  • 3,506
  • 1
  • 21
  • 33
0

My bad. As pointed out by @mm759, "src/main/resources" was picked up. I was confused because of the way logging worked.

"java.util.logging.config.file=" should be present either as a VM argument or present inside the .properties file.

user104309
  • 690
  • 9
  • 20