Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Depending on com.sun.javadoc from tools.jar (Sun JDK) in Eclipse

Tags:

java

eclipse

One of our plugins requires an installed JDK, not just an JRE. We need com.sun.javadoc and friends from tools.jar. I do not think Sun's license will allow redistributing tools.jar (which is not necessary if you already have a JDK anyway).

It also seems there is no way in Eclipse to specify a JDK as a dependency. All answers in the Eclipse newsgroups suggest that end users will have to configure their Eclipse properly first.

Do you know any workaround that will make this dependency obvious to users of our plugin, just by using Eclipse's on-board mechanisms for dependencies? It seems this package is not even valid for Import-Package in the manifest, unlike e.g. com.sun.jdi.

(As a work-around, currently we can only warn on plugin activation that this library is missing.)

like image 567
Volker Stolz Avatar asked Oct 03 '09 07:10

Volker Stolz


1 Answers

Since eclipse offers an OSGi environment, you could refer to the article "Exposing the boot classpath in OSGi", and try using:

  • a System Packages declaration
  • a Extension Bundles (Fragment) declaration
  • or boot delegation

By specifying the JDK packages you need, the OSGI framework will attempt to load them (and fail if there are not here).
By specifying one specific to JDK5 or JDK6, you could even ensure the right version of the JDK.

The OSGi spec allows the Framework (through its system bundle) to export any relevant packages from its parent class loader as system packages using the org.osgi.framework.system.packages property.
As repacking the hosting JDK as a bundle isn't a viable option, one can use this setting to have the system bundle (or the bundle with id 0) export these packages itself.
Most of the OSGi implementations already use this property to export all the public JDK packages (based on the detected JDK version). Below is a snippet from an Equinox configuration file for Java 1.6:

org.osgi.framework.system.packages = \
  javax.accessibility,\
  javax.activity,\
  javax.crypto,\
  javax.crypto.interfaces,\
  …
  org.xml.sax.helpers

Using this property, one can add extra packages that will be loaded and provided by the framework and that can be wired to other bundles.

org.osgi.framework.system.packages = \
  javax.accessibility,\
  javax.activity,\
  …
  org.xml.sax.helpers, \
  special.parent.package

Note: the simpler solution of specifying Bundle-RequiredExecutionEnvironment is only for the JRE, not the JDK...


That kind of configuration need to be part of the config.ini of the Equinox framework (see this example for Jetty and its config.ini).
In your case, it would be declared in the config.ini of your fragment.

like image 94
VonC Avatar answered Oct 21 '22 15:10

VonC