Urgent help needed:
I am trying to connect SFTP through Java Snippet (for some security reason, I cannot use SSH Node. In my case, SSH node doesn’t work) in KNIME to read the content of the XLSX file (Connection working fine. Problem is in reading XLSX).
I tested the code in Eclipse, and it runs perfectly fine (the dependencies I used are attached below).
Now, when I implemented this code in the KNIME, I got:
WARN Java Snippet 3:22 Evaluation of java snippet failed for row “Row0”.The exception is caused by line 102 of the snippet. Exception message (NoSuchMethodError): 'org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream$Builder org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.builder()’
While I used the same libraries here:
The problem is that it says the method is not found, while that commons-io jar has the method.
I know this because the Eclipse project gave me the same issue, which worked when I changed the version of the commons-io. Now, why is KNIME giving me this issue? And how to solve this.
Hi @prashant7526 , could you upload a minimal java snippet that demonstrates the problem, as I think you are much more likely to get assistance if we can see the actual code that is failing.
From experience, debugging this kind of issue even when I have my own code visible in front of me can be challenging, but to do it without being able to see the java call that is causing the error is almost impossible. thanks.
This isn’t a solution to your specific problem but I’m wondering if it can give us any pointers. I have a component on the hub that I have just updated to work with KNIME 5.2
It’s purpose is to read an xlsx file, and duplicate a specified sheet, writing it out to a new file with a comma delimited list of sheet names.
I was wondering if it could be adapted to read your xlsx file. (i.e. unlink the component, open it and take a look at the Java Edit Variable being used for the java calls)
It also uses
import org.apache.poi.xssf.usermodel.*;
and the following XSSFWorkbook call …
try (FileInputStream inputStream = new FileInputStream(inputFilePath);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
...
...
which I think you’d need to replace with your call:
Hi @takbb, thanks for directing me to these POI. I didn’t know that these libraries were already there.
I removed my external libraries and added all these below (I know it looks stupid; I added all the versions. I will start cleaning it), and it works like a charm.
WOW! I am learning from my experience as of now: If coding Java, try to use libraries that come with KNIME before adding external jars (it might conflict with the built-in libraries). I think this is what happened in my case.
That’s great @prashant7526 , the one problem I found so far with using the specific “additional bundles”, is that when I wrote that above component for KNIME 4.7, it then failed today when I tried it with 5.2 (hence the new 5.2 version!). This was because the v4.7 bundle it was looking for no longer existed.
I’m not sure at the moment what the best way to deal with that is. It would be nice if they had some kind of “logical name” or a level of abstraction to allow it to pick up newer versions automatically, but I guess I will have to leave something for “future-me” to enjoy fixing
True, normally, the latest version does carry the classes, interfaces, and methods; sometimes, they deprecate as well. You have a point: I don’t want my nodes (if I create one) or the Java Snippet to fail in a newer version and someone has to write it again. KNIME should keep the older version abstract or something.
So in this case it wasn’t a big change to make it work, but even so it’s a component I’ve made public that will just suddenly stop working because the user has updated their KNIME, so that could be problematic if somebody relies on it!
Once its working, you make a note of the bundle names, but without the version numbering, and you place the above component ahead of the java snippet, and give it the comma separated list of bundle names:
You then configure the flow variables for the java snippet to accept the AdditionalJavaBundles flow variable:
Provided that the jar files contain no API differences, or additional jars are needed, the same snippet should work in both KNIME releases even though there is a major version difference between bundles