The use of exec:java
will not work as desired, even if systemProperties
is used to pass in java.util.logging.config.file
, as LogManager has already been configured for maven and exec:java
executes your class in process.
Using exec:exec
works as expected, and the magic argument <classpath/>
mirrors exec:java
experience:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-ea</argument>
<argument>-classpath</argument>
<!-- uses dependencies and build directory -->
<classpath/>
<argument>-Djava.util.logging.config.file=${basedir}/logging.properties</argument>
<argument>org.example.Logging/argument>
</arguments>
</configuration>
</plugin>
For completness:
handlers=java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = ALL
org.example=FINE
For completeness:
package org.example;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Level;
public class Logging {
static final Logger LOGGER = Logger.getLogger("org.example");
public static void main(String args[]) {
LOGGER.info("Welcome to Logging Example");
LOGGER.config("Checking java.util.logging.config.file");
if( System.getProperties().containsKey("java.util.logging.config.file") ){
File config = new File(System.getProperty("java.util.logging.config.file"));
LOGGER.config("java.util.logging.config.file="+config);
}
LOGGER.fine("Everything is fine...");
LOGGER.finer("Everything is finer...");
LOGGER.finest("Everything is finest...");
}
}