Hi: all, I am writing a plugin to integrate knime work flow with Jena (http://jena.sourceforge.net/) by adding a new database node JenaDatbasereader. In order to do that, I have to write a new DbReaderConnection class because Jena has it's own way of creating a connection to the database and then querying the data. when I try to instantiate the new DbReaderConnection class which I called JenaDbReaderConnection from the DBReaderNodeModel class (which I called JenaDBReaderNodeModel), I am having a class not found exception from the class loader. I wonder why is that? Does Knime uses it's own class loader to load the class and is there any security check or some thing that causes the class loader not to load the new JenaDatabaseReaderConnection class. Can some one shed some light on this issue.
Thanks in advance.
when I try to instantiate the new DbReaderConnection class which I called JenaDbReaderConnection from the DBReaderNodeModel class (which I called JenaDBReaderNodeModel), I am having a class not found exception from the class loader. I wonder why is that? Does Knime uses it's own class loader to load the class and is there any security check or some thing that causes the class loader not to load the new JenaDatabaseReaderConnection class. Can some one shed some light on this issue.
There is an issue with class loading in Eclipse when a class in plugin A wants to load a class in plugin B and
plugin A does not depend on plugin B, because each plugin uses its own classloader. That is for example the case with all NodeFactories. They are instantiated from the org.knime.core-plugin when a workflow is loaded but reside in some other plugin which the core-plugin does not depend on. I'm not sure if this is the case in your example. But you may try to use KNIME's GlobalClassCreator to load a class which queries all plugins' classloaders.
If however, all classes your are dealing with are in the same plugin, this should work in any case out-of-the-box. Which class excactly is not found? Any of your own classes or any of the Jena classes. Maybe they are in a JAR-file and the JAR-file is not listed in the Runtime-classpath of your plugin? Adding a JAR to the Project Libraries (via Project Properties -> Libraries) does not work when you are dealing with plugins, the JARs must be listed in the MANIFEST.MF under Bundle-ClassPath instead.
In order to use a 3rd party lib, do the following
Create a "/lib" directory in your project and copy the 3rd-party lib (the .jar) there.
In your plugin.xml file (in the root of your project) add the jar to the classpath Tab "Runtime", section "Classpath", use "Add..." and browse to your lib.
Another common mistake is to not export the package that contains the NodeFactory (depending on when you get the error message). In the same "Runtime" tab, "Add..." the package your JenaDBReaderNodeFactory is located in (the one that is registered with the node extension point of KNIME's node repository).
Also, make sure the jar that is build for your project (defined in the "Build" tab, section "Runtime Information"), is listed in the "Classpath" section of the "Runtime" tab. If it doesn't appear here, use "New..." to add it.
I hope these things help resolving your problem.
As a side note The KNIME workbench is not using it's own special classloader, it is using the loader that comes with Eclipse and its plug-in mechanisms.
Thanks Peter and Thor for your tips, but still I am having some issues that could be eclipse specific and may be you guys can help me there.
1. I created a lib directory at the root folder and put all the dependent jars there
2. But when I go to plugin.xml->Runtime->add and plugin.xml->Build->Runtime information->"Add Libarary" tabs, I am unable to browse the "lib" directory with my external jars. The only 3 options that add tab shows are bin, src, and met-inf, even if you put the lib directories under one of these folders. It might be because of some settings in build.properties or etc, that I am not sure how to hack.
3. Finally I hacked the manifest file by adding all the dependent jars to Bundle-ClassPath.
4. After this I can see these jars both on Runtime and build "add" tab, so I added these jars to the classpath of both these tabs.
5. When I executed the code I am still having the same error. I wonder do I have to edit plugin.xml because I am not sure how manifest will know the path of the jar ( \JenaDatabaseReader\lib\all.jars) even though I added these jars in the manifest file?
Sorry for my long post. and thanks again for both of your help.
Thanks guys I got it, forget about my last post, I was able to add the jar in Build and Runtime folder by using the new tab and then .\lib\all.jars.
Thanks both of you for your help.