Search code examples
javamaven-2derby

Getting rid of derby.log


I'm using the Apache Derby embedded database for unit testing in a Maven project. Unfortunately whenever I run the test I end up with the derby.log file in the root of the project. The database itself is created in the target directory (jdbc:derby:target/unittest-db;create=true) so that is not a problem. After consulting the reference guide I tried setting the logDevice parameter on the JDBC url (jdbc:derby:target/unittest-db;create=true;logDevice=/mylogs) but that seems to be for a different log, hence derby.log still appears.

Any help is much appreciated.


Solution

  • You can get rid of derby.log file by creating the following class

    public class DerbyUtil {
        public static final OutputStream DEV_NULL = new OutputStream() {
            public void write(int b) {}
        };
    }
    

    and setting the JVM system property derby.stream.error.field, for example, using the following JVM command-line argument:

    -Dderby.stream.error.field=DerbyUtil.DEV_NULL
    

    Credit to whom it is due.