摆脱 derby.log
我正在使用 Apache Derby 嵌入式数据库在 Maven 项目中进行单元测试。 不幸的是,每当我运行测试时,我都会在项目根目录中看到 derby.log 文件。 数据库本身是在 target
目录 (jdbc:derby:target/unittest-db;create=true
) 中创建的,因此这不是问题。 在查阅参考指南后,我尝试设置logDevice
参数 (jdbc:derby:target/unittest-db;create=true;logDevice=/mylogs
) 但这似乎是针对不同的日志,因此 < code>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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
Derby 允许您使用 Java 系统属性
derby.stream.error.file
。 默认值为“derby.log”。为了在 Maven Surefire 测试阶段摆脱 derby.log,我只需在插件配置中添加属性定义,如下所示:
Derby lets you specify the name of the file to which the error log messages are written using the Java system property
derby.stream.error.file
. The default value is 'derby.log'.To get rid of
derby.log
during the Maven surefire testing phase, I just add the property definition in the plugin configuration as follows:您可以删除
derby.log
并设置 JVM 系统属性
derby.stream.error.field
,例如,使用以下 JVM 命令行参数:归功于应得的人。
You can get rid of
derby.log
file by creating the following classand setting the JVM system property
derby.stream.error.field
, for example, using the following JVM command-line argument:Credit to whom it is due.
在 derby.properties 文件中包含以下内容:(
或
在 Windows 上)
Include the following in your derby.properties file:
( or
on Windows)
对于集成测试,情况可能比简单的 surefire 属性更棘手。
在
maven-failsafe-plugin
中指定属性derby.stream.error.file
将不起作用,因为服务器环境不是从该插件继承的(显然使用maven-surefire-plugin
没有区别)。相反,您需要修改实际的服务器启动插件。 以下示例适用于
maven-jetty-plugin
:请注意,由于某种原因,我们使用
systemProperty
而不仅仅是 Surefire 解决方案中的property
。For integration tests the situation might be a bit more tricky than the simple surefire property.
Specifying the property
derby.stream.error.file
in themaven-failsafe-plugin
will not work as the server environment does not inherit from that plugin (obviously usingmaven-surefire-plugin
makes no differences).Instead you need to modify the actual server start plugin. The following example is for the
maven-jetty-plugin
:Note that for some reason we use
systemProperty
and not justproperty
as in the surefire solution.您还可以将 derby home 设置为
target/derby
或target
via:,然后使用 JDBC URL
jdbc:derby:unittest-db;create=true< /代码>。
然后 derby.log 将出现在右侧文件夹中。
You can also just set derby home to
target/derby
ortarget
via:and then use the JDBC URL
jdbc:derby:unittest-db;create=true
.Then derby.log appears in the right folder.
如果您无权访问配置,可以在建立连接之前执行以下操作:
If you don't have access to the configuration, you can execute this before making the connection:
我想出了另一个解决方案。 试试这个; 它对我有用。 我在这里所做的是更改了 System.stream.error.file 路径并将其设置为属性文件下存在的属性之一。 只需将下面给出的代码添加到您的 applicationContext.xml 文件中即可。
I have came up with another solution. Try this out; it worked for me. What I am doing here is I have changed the System.stream.error.file path and set it to one of the properties present under my property file. Just adding the below given code to your applicationContext.xml file will work.
这不是您的 derby.log 文件问题的解决方案(很多人已经展示了如何解决),而是一个建议。 为什么不使用 derby-maven-plugin 进行测试? 它将
derby.log
文件放置在target/derby
下,因此不会留下任何垃圾。如我的回答中所述,您可以通过我编写的 derby-maven-plugin 使用 Derby 作为数据库,该插件可以在 上找到GitHub 和通过 Maven Central。
This is not a solution to your
derby.log
file problem, (which numerous people have already shown how to resolve), but rather -- a suggestion. Why not use the derby-maven-plugin for your tests? It places thederby.log
file undertarget/derby
, hence not leaving any litter.As described in my answer here, you can use Derby as your database via the derby-maven-plugin which I wrote and is available on GitHub and via Maven Central.