2
votes

I need to execute a java jar file from Spoon.

The program has only one class, and all I want is to run it with or without parameters.

The class is named "Limpieza", and is inside a package named:

com.overflow.csv.clean

I have deploy the jar to:

C:\Program Files (x86)\Kettle\data-integration\lib

And from a Modified JavaScriptValue step, I am calling it this way:

var jar = com.everis.csv.clean.Limpieza;

This is not working at all, is there a way around to make it work? Also would be nice to have a way to see the logs printed by the program when it runs. I am not getting any error when I run the transformation.

Thanks.

3

3 Answers

2
votes

Spoon will load any jar files present in its

data-integration\lib

folder and its subfolders during startup, so if you want to access classes from a custom jar, you could place the jar here.

So you need to create a custom jar and place the jar in

data-integration\lib

location.

While calling a custom class in "Modified Java Script Value" or in "User Defined Java Class step" you should call with fully qualified name. For example
var jar = com.everis.csv.clean.Limpieza.getInstance().getMyString();

Note: After placing the jar, make sure you restart the Spoon.

If still does not work please attach the Pentaho.log (data-integration-server/logs/Pentaho.log) and catalina.out(data-integration-server/tomcat/logs) logs

1
votes

The answer was to create a User Defined Java Class (follow the guide Rishu pointed), and here is my working code:

import java.util.*;
import com.everis.csv.Cleaner;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    Cleaner c = new Cleaner();
    c.clean();
    // The rest of it is for making it work
    // You will also need to make a Generate Rows step that inputs a row to this step. 
    Object[] r = getRow();

    if (r == null) {
        setOutputDone();
        return false;
    } 
    r = createOutputRow(r, data.outputRowMeta.size());
    putRow(data.outputRowMeta, r);

    return true;
}