所以,我使用apache commons日誌記錄,因爲我也使用PDFBox,並且我只想保持一致。我想在幾分鐘內設置它,以便我可以使用日誌條目來調試我的應用程序中的問題。Commons Logging:不會檢測屬性文件
問題是,我的commons-logging.properties文件從未被檢測到。沒有檢測到我的配置設置。我無法改變日誌級別或做任何事情。我所得到的是我的信息條目,採用默認格式。
我正在使用Maven構建的項目,並且該文件位於我的資源目錄的根目錄中。該目錄中的所有其他內容在類路徑中都是可檢測的,僅此而已。
這裏是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pilotfish</groupId>
<artifactId>PDFViewer</artifactId>
<version>1.0</version>
<properties>
<apache.commons.io.version>2.4</apache.commons.io.version>
<apache.commons.logging.version>1.2</apache.commons.logging.version>
<apache.fontbox.version>1.8.11</apache.fontbox.version>
<apache.pdfbox.version>1.8.11</apache.pdfbox.version>
<java.version>1.7</java.version>
<maven.assembly.plugin.version>2.5.5</maven.assembly.plugin.version>
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.jar.plugin.version>2.6</maven.jar.plugin.version>
<maven.source.plugin.version>3.0.0</maven.source.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${apache.commons.io.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${apache.commons.logging.version}</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
<version>${apache.fontbox.version}</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>${apache.pdfbox.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<configuration>
<archive>
<manifest>
<mainClass>com.pilotfish.eip.modules.pdfviewer.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.plugin.version}</version>
<configuration>
<outputDirectory>${project.build.directory}/classes/source/</outputDirectory>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
這是我commons-logging.properties文件。
# Commons Logging Properties
# Doesn't seem to work... so annoying
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
# JDK Handlers
handlers=java.util.logging.ConsoleHander
# Default log level
.level=DEBUG
# Log Formatter
java.util.logging.ConsoleHander.formatter=com.pilotfish.eip.modules.pdfviewer.log.LogFormatter
.formatter=com.pilotfish.eip.modules.pdfviewer.log.LogFormatter
我只是想在這裏做一些簡單的事情。我不在乎任何複雜的東西,我只想讓我的調試語句正常工作。這是不正確的,這不會被發現。
在此先感謝。
嗨,你可以找到你的生成JAR的屬性文件?如果沒有 - 你可以在程序集插件配置中添加一個文件部分嗎? / outputDirectory>。有關示例,請參見[https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html]。同時我強烈建議看看[shade-plugin](https://maven.apache.org/plugins/maven-shade-plugin/),如果你想構建一個超級jar。 –
javapapo
我只是將log4j.jar添加爲額外的jar,幷包含log4j.properties或log4j.xml文件。 Commons logging允許你保留自己喜歡的記錄器。 –
是的,看到我的評論下面有關我做了什麼的細節,但我基本上手動檢索資源作爲一個流,使其工作。 – user2223059