How do I attach the sources for a library bundle in OSGi/Equinox/Eclipse?

和自甴很熟 提交于 2019-12-01 06:57:31

If you add the source files to their own jar then create a META-INF/MANIFEST.MF file with an 'Eclipse-SourceBundle' entry which specifies the symbolic name of your library bundle. Below is an example I have from the Felix jar:

Manifest-Version: 1.0
Eclipse-SourceBundle: org.apache.felix.main;version="4.0.1";roots:="."
Bundle-Version: 4.0.1
Bundle-Name: Apache Felix Framework
Bundle-ManifestVersion: 2
Bundle-Vendor: The Apache Software Foundation
Bundle-SymbolicName: org.apache.felix.main.source

To be able to view the source in Eclipse make sure this source jar is in your PDE target (Windows->Preferences->Plugin Development->TargetPlatform). If your using Eclipse itself as the target platform just drop it in to your eclipse plugins folder.

You can include the sources under the OSGI-OPT/src path of the bundle; then they will be seen by the Eclipse debugger (not sure about other IDEs, as I only use Eclipse). I find this a lot simpler than creating a separate source bundle, because one artefact is easier to manage than two, and if you build with Bnd or Bndtools, we create bundles like this by default.

In the rare cases when you need to deploy to a resource-constrained environment, you can simply remove the OSGI-OPT directory from the bundle; this name is a convention for optional data that can be removed without affecting the operation of the bundle.

Incidentally our approach is inspired by UNIX executables, which often contain extra debugging symbols, and the strip command that removes them to create a smaller executable when desired.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!