[ACCEPTED]-Getting rid of derby.log-derby

Accepted answer
Score: 50

Derby lets you specify the name of the file 6 to which the error log messages are written 5 using the Java system property derby.stream.error.file. The default 4 value is 'derby.log'.

To get rid of derby.log during 3 the Maven surefire testing phase, I just 2 add the property definition in the plugin 1 configuration as follows:

Score: 23

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

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

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


Credit to whom it is due.

Score: 8

Include the following in your derby.properties 1 file:


( or


on Windows)

Score: 3

For integration tests the situation might 8 be a bit more tricky than the simple surefire property. Specifying 7 the property derby.stream.error.file in the maven-failsafe-plugin will not work as the 6 server environment does not inherit from 5 that plugin (obviously using maven-surefire-plugin makes no differences).

Instead 4 you need to modify the actual server start 3 plugin. The following example is for the 2 maven-jetty-plugin:

            <!-- Get rid of that missplaced derby.log. -->

Note that for some reason we use systemProperty and not 1 just property as in the surefire solution.

Score: 3

You can also just set derby home to target/derby or 2 targetvia:

System.setProperty("derby.system.home", new File("target/derby").getAbsolutePath());

and then use the JDBC URL jdbc:derby:unittest-db;create=true. Then derby.log 1 appears in the right folder.

Score: 2

I have came up with another solution. Try 6 this out; it worked for me. What I am doing 5 here is I have changed the System.stream.error.file 4 path and set it to one of the properties 3 present under my property file. Just adding 2 the below given code to your applicationContext.xml 1 file will work.

<bean id="setDerbyLog" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  <property name="targetClass"><value>java.lang.System</value></property>
  <property name="targetMethod"><value>setProperty</value></property>
  <property name="arguments">
Score: 2

If you don't have access to the configuration, you 1 can execute this before making the connection:

System.setProperty("derby.stream.error.field", "MyApp.DEV_NULL");
Score: 0

This is not a solution to your derby.log file problem, (which 8 numerous people have already shown how to 7 resolve), but rather -- a suggestion. Why 6 not use the derby-maven-plugin for your tests? It places the 5 derby.log file under target/derby, hence not leaving any litter.

As 4 described in my answer here, you can use Derby as your 3 database via the derby-maven-plugin which 2 I wrote and is available on GitHub and via Maven 1 Central.

More Related questions