Problem using a Java-method in an external .jar I created (Java Snippet)

Hello everyone!!

I'm trying to use Java Snippet (Standard and simple version) to do some stuff with a .JAR I designed.

I'm publishing an example workflow to understand the problem I'm having. In this case, I designed a class that has tow methods to obtain the average of the values stored in a vector (double[]) (a simple example to start building more complex things). But, when I see the result in the output port I only see missing values (?). So, I want to know how to use a .JAR with the Java Snippet nodes.

In this case, the data for the example is the same "iris.csv". I just drop the class column, and try to obtain the average per row. The .JAR I'm working with is located inside the "Java Snippet"-node folder (so you could redirect the direction to your local computer).

The class inside the JAR is named "JarKnime" and it has two methods (one for the class, and one of objects):

 

    public double meanOfVector(double[] vctr) {
        double mean = 0.0;
        for (int i = 0; i < vctr.length; i++) {
            mean += vctr[i];
        }
        return mean / vctr.length;
    }
   
    public static double meanOfVector_staticMethod(double[] vctr) {
        double mean = 0.0;
        for (int i = 0; i < vctr.length; i++) {
            mean += vctr[i];
        }
        return mean / vctr.length;
    }

 

Thanks for the help you could provide here!!! If you have a simple example, it will be welcome.

 

JarKnime ojk = new JarKnime(); is throwing:

 

java.lang.UnsupportedClassVersionError: jar_knime/JarKnime
    at JSnippet.snippet(JSnippet.java:54)
    at org.knime.base.node.jsnippet.JavaSnippetCellFactory.getCells(JavaSnippetCellFactory.java:217)
    at org.knime.core.data.container.RearrangeColumnsTable.calcNewCellsForRow(RearrangeColumnsTable.java:503)
    at org.knime.core.data.container.RearrangeColumnsTable.calcNewColsSynchronously(RearrangeColumnsTable.java:424)
    at org.knime.core.data.container.RearrangeColumnsTable.create(RearrangeColumnsTable.java:342)
    at org.knime.core.node.ExecutionContext.createColumnRearrangeTable(ExecutionContext.java:369)
    at org.knime.base.node.jsnippet.JavaSnippet.execute(JavaSnippet.java:782)
    at org.knime.base.node.jsnippet.JavaSnippetNodeModel.execute(JavaSnippetNodeModel.java:133)
    at org.knime.core.node.NodeModel.execute(NodeModel.java:706)
    at org.knime.core.node.NodeModel.executeModel(NodeModel.java:555)
    at org.knime.core.node.Node.invokeFullyNodeModelExecute(Node.java:1131)
    at org.knime.core.node.Node.execute(Node.java:927)
    at org.knime.core.node.workflow.NativeNodeContainer.performExecuteNode(NativeNodeContainer.java:559)
    at org.knime.core.node.exec.LocalNodeExecutionJob.mainExecute(LocalNodeExecutionJob.java:95)
    at org.knime.core.node.workflow.NodeExecutionJob.internalRun(NodeExecutionJob.java:179)
    at org.knime.core.node.workflow.NodeExecutionJob.run(NodeExecutionJob.java:110)
    at org.knime.core.util.ThreadUtils$RunnableWithContextImpl.runWithContext(ThreadUtils.java:328)
    at org.knime.core.util.ThreadUtils$RunnableWithContext.run(ThreadUtils.java:204)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.knime.core.util.ThreadPool$MyFuture.run(ThreadPool.java:125)
    at org.knime.core.util.ThreadPool$Worker.run(ThreadPool.java:248)

 

I've made a dummy project in eclipse and tried to run your method. It works in Java 8 and not Java 7, recompile your Jar for Java 7 which is what KNIMe uses and I suspect it will work. 

Cheers

Sam

Hello Sam!!

 

Thanks for taking your time to help me...

 

Yes, the problem with the JAR I created was the Java version I used... I compiled with Java 7 and worked perfectly.

 

Thanks again.