I have been trying to access various classes from the org.knime.core bundle via a Java Snippet.
I have added the bundle under the ‘Additional Bundles’ tab, but can only import the classes org.knime.core.node.KNIMEConstants and org.knime.core.node.NodeLogger.
I can see a number or related tickets which seem to have gone unanswered:
Is there a solution to this problem, or even an open ticket on it?
I right now cannot give you details on why exactly this is not available in the Java Snippet node as expected.
I can say however, that it has to do with the way the org.knime.core plugin/bundle is represented on disk (in p2 terms, how it is installed in the resp. bundle pool). Concretely, if you look in the AP installation directory in the folder plugins, you’ll see that some plugins are jars and some are directories.
If they are directories, they will (always, as far as I can see, and certainly for sure in the case of org.knime.core) contain a correponding jar file. That file is already set as the Bundle-ClassPath in the Manifest.MF.
Based on this, I can offer you the workaround to add that jar file under “Additional Libraries” instead of including it in “Additional Bundles”.
The drawback is that this path contains the bundle version, which means it will change with an update.
However, you can also supply the list of “Additional Libraries” via the flow variable jarFiles, so it should be not too hard to add a couple of nodes that query the folder from that directory.
I may be able to help with that… I have a component…
I already had this component to go try to find bundles to get round the problem of things changing every time there was a new KNIME update, and based on your comments above, I’ve added the option to search subfolders of the bundles for required jars.
It should work the same way with both Java Snippet and Java Edit Variable…
As you can see from the screenshot, when the additional libraries has been specified using the flow variable, the syntax highlighter of the java editor does not recognise that the package is present. However, as you can also see from the node state and the output, it does actually compile and execute , returning the output “(WFM) ROOT (IDLE)” in this case as a flow variable.
So, possibly for editing the java, you’d want to add the required additional library in manually, but then for “shipping”, you could add it in using the flow variable from the “Collect Required Plugin Jars” component.
In the component you specify a file name pattern for it to search, so this kind of becomes an “abstraction layer” instead of being tied to a physical version number.
I have this component in my “experimental” folder on the hub, but its available to try, and happy to get feedback and suggestions if it is helpful.
Thanks @BenjaminMoser and @takbb - I was about to try writing something similiar to your approach myself.
I have also come across the syntax highlighting error previously (I used a similar approach to @takbb 's to bring in some maven dependencies in another snippet a while back) - I think it comes about as a result of the variable value substitution of for the settings values in the UI not being replaced until sometime during either the configure or execute phases, so may not be solvable (I think it’s the same issue that means you need to put a nonsense value in some node settings even though you replace it with a meaningful value from the flow variables because the dialog component won’t accept an empty input)
With the additional subfolder searching in that component, which I only just added here based on the comments in this thread, it could possibly do with some additional optimisation and/or look at caching the jar location after first execution (on a given KNIME version?), as I think this may otherwise add an unwelcome delay, so will be interested to know how you get on, or if you make other refinements to it, or have suggestions.
Good point about the likely problem with the flow variable. I hadn’t thought about it in terms of maybe needing a populated placeholder value.