[ACCEPTED]-Getting rid of derby.log-derby
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:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>derby.stream.error.file</name>
<value>target/derby.log</value>
</property>
</systemProperties>
</configuration>
</plugin>
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:
-Dderby.stream.error.field=DerbyUtil.DEV_NULL
Include the following in your derby.properties 1 file:
derby.stream.error.file=/dev/null
( or
derby.stream.error.file=\\Device\\Null
on Windows)
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
:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Get rid of that missplaced derby.log. -->
<systemProperty>
<name>derby.stream.error.file</name>
<value>${project.build.directory}/derby.log</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
Note that for some reason we use systemProperty
and not 1 just property
as in the surefire solution.
You can also just set derby home to target/derby
or 2 target
via:
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.
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">
<list>
<value>derby.stream.error.file</value>
<value>${derby.stream.error.file}</value>
</list>
</property>
</bean>
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");
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
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.