Eclipse RCP中的自定义ConsoleAppender提供循环依赖关系

时间:2013-09-17 09:35:58

标签: java eclipse-plugin log4j eclipse-rcp fragment

我正在开发Eclipse RCP应用程序,我希望有一个自定义的ConsoleAppender,因此我可以将所有日志重定向到日志窗口。 log4j插件和log4j片段(包含log4j.properties)创建了一个我成功使用的单元。 我还创建了一个'扩展'插件,其中包含我的代码以捕获日志数据。看看2个插件和下面的片段。

rcp_external_log4j (plugin containing the jar file)
  log4j-1.2.16.jar

rcp_external_log4j_fragment (containing the log4j.properties file)
  log4j.properties (which points to VirtualConsol)

rcp_external_log4j_extension (plugin containing the VirtualConsol)
  src/VirtualControl.java (which extends ConsoleAppender)

当我从Eclipse调试环境中执行我的项目时,一切正常。 VirtualConsole按预期转发所有日志记录数据。

但是,当我尝试将带有“Eclipse产品导出向导”的项目导出到独立的可执行文件时,我遇到以下问题:

Problem Occured
'Export Product' has encountered a problem.
A cycle was detected when generating the classpath
rcp_external_log4j_extension
rcp_external_log4j
rcp_external_log4j_extension

VirtualConsole扩展了ConsoleAppender,并且还从代码的其他部分调用。 由于ConsoleAppender的扩展,VirtualConsole位于rcp_external_log4j_extension并使用log4j。 rcp_external_log4j使用rcp_external_log4j_extension,因为rcp_external_log4j插件与rcp_external_log4j_fragment捆绑在一起,后者引用log4j.properties文件中的VirtualConsole。

问题:如何在不获得循环依赖的情况下编写自己的ConsoleAppender?我可以把代码放在片段中吗?我可以将代码放在包含jar文件(rcp_external_log4j)的插件中吗?我尝试了那两次尝试但没有成功......

感谢任何帮助


问题解决了。 src与jar文件放在同一个插件中。

rcp_external_log4j (plugin containing the jar file)
  log4j-1.2.16.jar
  src/VirtualControl.java (which extends ConsoleAppender)

rcp_external_log4j_fragment (containing the log4j.properties file)
  log4j.properties (which points to VirtualConsol)

和'src'被添加到rcp_external_log4j的类路径中。在MANIFEST.MF中看到

Bundle-ClassPath: log4j-1.2.16.jar,
 src/

这样,VirtualConsole既可以从片段中使用,也可以从其他代码中使用。

build.properties应该包含:

jars.compile.order = src/
source.src/ = src/
output.src/ = bin/

表示要包含在导出产品中的代码。

1 个答案:

答案 0 :(得分:0)

我认为rcp_external_log4j_fragment在构建路径中不需要rcp_external_log4j_extension,只能在清单中。这应该删除循环。