【问题标题】:Custom log4j appender is not found in my Eclipse plugin在我的 Eclipse 插件中找不到自定义 log4j 附加程序
【发布时间】:2017-04-08 12:32:08
【问题描述】:

我尝试在我的 Eclipse 插件项目中为 log4j 使用自定义附加程序 (sentry-raven),但 log4j 找不到它。 jar 文件 (raven-log4j-7.8.6.jar) 包含缺少的附加程序 ("com.getsentry.raven.log4j.SentryAppender"),但 Eclipse 的类加载器找不到它。

这是我到目前为止所做的:

  • 我将 jar 文件放在项目根目录下的 /lib 文件夹中
  • 我的插件清单有 Eclipse-RegisterBuddy: org.apache.log4jRequire-Bundle: org.apache.log4jBundle-ClassPath: lib/, . 条目

我的build.properties 看起来像

bin.includes = META-INF/,\
               plugin.xml,\
               .,\
               lib/raven-7.8.6.jar,\
               lib/raven-log4j-7.8.6.jar

我在插件的start(BundleContext context) 方法中添加了以下代码,以便更好地控制何时加载 log4j 属性文件。

URL installURL = getBundle().getEntry("/");
String installPath = Platform.asLocalURL(installURL).getFile();
PropertyConfigurator.configure(installPath +"/src/log4j.properties");

调试器越过最后一行代码时,我会立即收到以下错误。

log4j:ERROR Could not instantiate class [com.getsentry.raven.log4j.SentryAppender].
java.lang.ClassNotFoundException: com.getsentry.raven.log4j.SentryAppender cannot be found by org.apache.log4j_1.2.15.v201012070815
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
...

log4j.properties 看起来像

log4j.rootLogger=WARN, default, Sentry
log4j.appender.Sentry=com.getsentry.raven.log4j.SentryAppender
..

【问题讨论】:

    标签: java eclipse-plugin log4j sentry


    【解决方案1】:

    来自 OSGI 规范本身:

    Bundle-ClassPath 标头定义了一个逗号分隔的 JAR 文件路径名或目录列表 (在包内)包含类和资源。

    您需要明确列出 raven jar 文件。

    【讨论】:

      【解决方案2】:

      我从 Manifest=>Dependencies 中删除了 org.apache.log4j 并手动添加了 log4j-1.215.jar(将其保存到 lib 文件夹并在 Manifest=> Runtime => Classpath 下添加了 jar 文件)

      然后我的自定义附加程序工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-24
        • 2015-06-11
        • 2011-04-28
        • 1970-01-01
        • 1970-01-01
        • 2014-12-23
        • 1970-01-01
        相关资源
        最近更新 更多