Depending on com.sun.javadoc from tools.jar (Sun JDK) in Eclipse - 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.)

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.

Related

What's the difference between Eclipse Packages and Plug-ins?

In Dependencies tab, I have a choice between plug-ins and packages.
What's the difference between them? For org.eclipse.compare, I have it in imported package and also in plug-ins.
I find the jar file in plugins directory, but I don't know where the package file of org.eclipse.compare is located.
In the export menu, it seems like that there seems to be only exporting to jar, not exporting a plugin or packages. How can I export packages?
ADDED
Based on this post - How to import a package from Eclipse? and shiplu's answer. This is what I came to understand. Please correct me if I'm wrong.
In eclipse, when I use come external class, I can use Quick-Assistant or Organize imports (Ctrl-Shift-O) to resolve the reference. Eclipse adds the package that contains the class in Imported Packages for the project that I'm working on. A package can contain multiple classes (types). Eclipse understands what plugin contains the package, and resolve the reference issues.
A plug-in (jar file) can contain multiple packages. By specifying a required plug-ins in the dependencies tab, we can reference all the packages (and classes in the packages) for all the java projects in the eclipse IDE.
And from my experience, I had to add all the dependencies in order to make headless RCP standalone (http://prosseek.blogspot.com/2012/12/headless-rcp-standalone.html).
An Eclipse plug-in is basically an OSGi bundle with additional plugin.xml file which Eclipse IDE understands and interprets.
So the answer to your question lies in the OSGi specification and the OSGi programming model, since, very simply put, Eclipse is an Application running on implementation of OSGi called Equinox.
OSGi is all about having modular applications and so it defines several levels of modularity.
One such level is a bundle-level (module-level) modularity and more fine grained level is the package level modularity.
So you can have your OSGi application (a set of bundles; eclipse is just that) which consists of db-bundle (which provides data store services), app-domain-bundle (which provides your application domain services) and remote-bundle (which exposes to the web your application via REST for example).
And then you say remote-bundle depends on domain-bundle which depends on db-bundle.
Which is all good, but cripples the inherent modularity OSGi provides, because you are basically restricting your application to specific implementations of db-bundle and remote-bundle i.e. to specific implementations of the services they provide.
Instead, you can establish the above dependencies not between bundles but between packages i.e. establish a service-level dependencies.
Then you say domain-bundle requires dbstore.service package to run, it doesn't care which bundle provides it it just needs an instance of this service to be able to work. So you can have multiple bundles providing implementations of the dbstore.service, and the domain-bundle can pick and choose at runtime what service to use.
It is really hard to explain OSGi concepts in just a several sentences, I'd really suggest you dig around the web on this and maybe even have a look at the OSGi specification.
Another way to explain it is to say that bundle/plug-in is a jar file with specific structure and metadata descriptors (MANIFEST.MF and plugin.xml), which describe its contents in Java language concepts - which java packages and services this specific jar contains and will expose to the OSGi runtime so that they can be consumed by other bundles. I.e. the bundle is the physical deployable entity while the descriptors are metadata about what actually is being deployed.
EDIT:
Package or Service-level dependencies also have some drawbacks, as Lii points out in the comments below, the main one being that it adds complexity and dynamics to the dependency model. Have a look at her or his comment below - it is worth reading!
You use Imported Packages when you want to use a specific package but do not care which plugin provides it. OSGI will choose one for you.
Eclipse plugins is something like extension to the IDE itself. But imported packages are actually packages that you'll use in your current project.
One is for development IDE another is for the project you are coding.

Making User-Made Java Classes Available To All Eclipse Projects

This is getting to me a bit.
What should be a straightforward and well worn procedure to do something all users need to do is anything but straightforward.
I made the Java class I want to add to all new Java projects into a JAR file.
And I got it into the JRE folder using Window > Prefs > Java > Installed JREs, etc.
But come runtime, the Java interpreter just doesn't see this class as attached to my projects.
Anyone know how this pesky one is fixed ?
I'm using Eclipse 3.6.2 Helios and JRE 7.
The JRE isn't really intended to be extended in this way. If you must store your shared libraries in the JRE, the ext folder should be used, rather than the top-level JRE folder. However, even this is usually a bad practice: Is putting external jars in the JAVA_HOME/lib/ext directory a bad thing?.
To add dependencies to your Eclipse projects, use the project's build path. To add dependencies at run-time, use the Java class path.
I would create a userlibrary and add the lib to the project setup. http://goo.gl/pEoto
Consider to use Maven to manage your dependencies.

Hibernate Setup in eclipse helios

How I can setup Hibernate for a Dynamic Web application by using Eclipse Helios? I am a newbe so please let me know if there is any example.
I tried for Java application and included all JARS and it worked fine. But don't understand how I can do it for Web application and test it.
I will use Struts2 so I will appreciate if I can get appropriate example or guidance.
Drop the jars in WEB-INF/lib. Those jars are automatically added by Eclipse to the project build path, and constitute (with the WEB-INF/classes directory and the container classpath) the classpath of the webapp.
http://hardik4u.wordpress.com/2008/09/02/struts-2-hibernate-3-integrationcomplete-using-eclipse/
https://stackoverflow.com/questions/4364923/struts2-and-hibernate-framework-create-in-eclipse
First, download Struts2, and import example WAR file into Eclipse. You can find it from the source folder: struts-2.3.1-all\struts-2.3.1\apps\struts2-blank.war
Second, you should install Eclipse Hibernate Plugin. Goto Window > Preferences > Install/Update > Available Software Sites and add following link and name it JBossTools or something.
http://download.jboss.org/jbosstools/updates/helios/
Depending on your needs you can install Hibernate Plugins for many project types. In this case, select web application plugin.
And after, you should include Hibernate Core libraries into your classpath. I would recomment Hibernate 3.6 and greater. Because it does not depend on asm (asm-3.3.jar, asm-commons-3.3.jar ...) anymore. If you use earlier versions you might encounter some problems, since Struts2 also depend on asm libraries.
Then create your database, and use following link to configure and generate model bean classes.
http://casteyo.wordpress.com/2007/06/06/conf_hibernate/
Now you don't need to write mapping files by yourselves. And with DAO factory pattern you have your way to finish your project.
Hope this helps, and Goodluck

Netbeans RCP module options. Felix, equinox or standard Netbenas module?

There are a few options for developing modules for Netbeans 7.0.1 RCP. I haven't found any clear comparison of them.
So I would like to know which of them is the easiest to:
develop
install by user (e.g. user could choose proper jar with module
from a repository )
Which makes to write less non-reusable code (e.g. when you want to make web application of used classes later)?
Which is the most popular?
The easiest way is to use the traditional Netbeans way - build nbm's. This is well tested and good feature. After building module you will get the "nbm" file with all needed info inside (additional jars, settings, etc.)
You can use "Module Update" features from Netbeans.
The other way is to build modules as osgi bundles.
This feature was introduced in 6.7 version and up to now it has some problems.
First of all, bundle in normal understanding is one jar. If your bundle depends on other jar (f.e. apache-commons:beanutils), you will need to pack this jar into your bundle jar (using maven-bundle-plugin) or to install "beanutils" as independent bundle. The first solution is not the best, because if in the future another bundle wants to use "beanutils" you will need to link new bundle with old one, even if they don't need this. This cause high cohesion between modules. Or you can pack "beanutils" into your new bundle, but this can cause classloading issues in osgi-framework.
So, if you need to install netbeans module, you just install one nbm file and that's all.
If you need to install bundle, you need to install all dependent bundles separately beside yours bundle.
Another things are, for now you can't configure osgi-framework, which embedded in netbeans and process of loading bundles has some differences from loading standard netbeans modules which can cause some "strange" issues.
I'm sure that guys from netbeans will fix this issues and they are moving in right direction, but for now, if you don't need bundles, don't use it.

Add system packages to PDE runtime configuration

I created an eclipse run configuration for a number of bundles. One of the bundles has a dependency to the following packages:
com.sun.mirror.apt,
com.sun.mirror.declaration,
com.sun.mirror.type,
com.sun.mirror.util
I believe these are part of the Sun Java JVM. When I add these packages as system packages to a Felix container, the bundle is loaded fine by that container.
However, I was unable so far to find out, how I can configure these packages as additional system packages for a run configuration in eclipse (I found how eclipse as a whole can be made aware by changing the config.ini).
EDIT: It seems that these classes are in the system library tools.jar. Or in my case, as I am using Mac OS X, they could be in classes.jar?
The OSGi specification defines a property called "org.osgi.framework.system.packages.extra" (explained in paragraph 4.2.2 that deals with launching properties) that allows you to specify extra packages that should be exported by the framework. Add your packages to that property in your run configuration and it should work.