creating nodes that reference external libraries

I'm trying to create a simple node that just references a single jar. It compiles ok in eclipse, but when I try to export it I get errors saying it can't import the packages, e.g:

# 6/29/07 11:44:03 AM BST
# Eclipse Java Compiler 0.671, 3.2.0 release, Copyright IBM Corp 2000, 2006. All rights reserved.
1. ERROR in E:\eclipse_knime_win32_developer_1.2.1\eclipse\workspace\TestExternalProj\src\syngenta\testing\
(at line 29)
The import com.syngenta cannot be resolved
1 problem (1 error)

Any ideas?


It seems that you put the jar into the classpath of the project itself.
For this reason, the jar is in the classpath when eclipse is compiling your code but when exporting the node as a plugin the project classpath is not used.
Therefore, you must put the jar into the Bundle-ClassPath of the file.
To do this, just open the manifest file (in folder Meta-inf). B.t.w. remove the jar from the project classpath.
In the editor select the "runtime" tab and press the add button in the classpath section.
Select your jar.
Now the export should work.

Awesome, that worked, thanks.


I have just started using KNIME, so still getting to grips with it.

I'm trying to create a node that can read in a specific file using an external library.

As well as doing the above, should I also include the jar as a library for the project?


By performing the steps described in my first post of this thread, you add a jar library to a plugin project. Normally, that's all you have to do to add external functionality provided as a jar. Adding the library also into the project's classpath (project context menu -> properties -> Java Build Path) is not necessary.

Thanks roadrunner, that works if I add the jar file somewhere in the project folder - not sure if there is a way of getting round this?

I'm getting another problem, the external library I'm using require properties files which are located in the jar. However it looks like they are not being read (at all or correctly) and I have tried to copy these directly to the plugin class directory without any success.

Any ideas?


hina4 wrote:
Thanks roadrunner, that works if I add the jar file somewhere in the project folder - not sure if there is a way of getting round this?

"Somewhere in the project folder" doesn't sound deterministic. I have added a FAQ that describes the details on what to pay attention to when using java libraries. Hope that helps (please complain if not).

Regarding the properties file: First of all, do you try to parse the properties file within your code (e.g. in your NodeModel class) or does some class file contained in the library (that you have no control of) attempt to read the file and then fails in doing so? If it's the latter one, we (eh, you) have a problem.

Otherwise, I suggest to have a look at the class "MolPropsLibrary" contained in the cdk plugin (in eclipse press Ctrl-Shift-T and then enter the name - theoretically it should bring you there). There is a static block that reads a properties file contained in one of the libraries. The key idea is to read the file using the plugin classloader and then read from the stream directly. File file = new File("someLocation.props") does not work - and even if it did in your runtime workspace it may not work once you export your plugin...

Good luck!