我的Eclipse插件中找不到自定义log4j appender

问题描述 投票:1回答:2

我尝试在我的Eclipse插件项目中为log4j使用自定义appender(sentry-raven),但是log4j找不到它。 jar文件(raven-log4j-7.8.6.jar)包含缺少的appender(“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
2个回答
0
投票

从OSGI规范本身:

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

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


0
投票

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

然后我的自定义appender工作。

© www.soinside.com 2019 - 2024. All rights reserved.