How do I “install” a log4j bundle?

2020-03-27 12:48发布

问题:

I've downloaded the code for an Eclipse plugin. The code uses log4j, but it doesn't just use it as a library (referred jar), but as a "bundle". So it doesn't compile because of the following reason:

Bundle 'org.apache.log4j' cannot be resolved

I'm not really sure what's the correct approach to solve this. I know how to add jars to a project, but how do I add "bundles"? Is it something I need to add to the entire Eclipse host?

I "solved" this by creating a new plugin project with no code but with the log4j jar included... but that doesn't feel like the right solution.

I've also found some places where "log4j bundles" are published, e.g.:

  • http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.apache.log4j&version=1.2.16
  • http://download.eclipse.org/tools/orbit/downloads/drops/R20110523182458/

But I'm not sure if that's what I need, if it matters where I get it from, and how to "install" it.

回答1:

I assume you are using the Eclipse Plugin Development Environment (PDE). In this case, the log4j bundle needs to be imported into the "Target Platform".

The Target Platform is like a repository of bundles (i.e. plug-ins) that replaces the "classpath" in traditional Java development. You can find the location of the target platform and modify it by going to Preferences -> Plug-in Development -> Target Platform.

HOWEVER before doing this I strongly recommend you take some time to learn a bit about what you are working on! If you want to develop an Eclipse Plug-in you should at least learn what a plug-in is, and how its dependencies work. If you read a bit about the subject you should not have to ask such an extremely basic question on Stack Overflow... it is covered in all the introductory tutorials and FAQs.