Pentaho/Kettle: Instead of running code from the code box in the "User defined Java Class", I am trying to compile it into a Jar, and run the jar file from the "User defined Java Class". I do this because my Java projects are too big, and in order to increase modularity. However, there are some problems with dependencies. Some methods are not available in the libraries, whereas there are some which are available in multiple libraries.
Zip file of the project I am trying to compile: https://drive.google.com/file/d/1H-RGGvH-h3zvLnF3qIVVIHnnB4vtwKvN/view?usp=sharing .
Code of the Gradle dependencies I am using:
dependencies {
compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core',
version: '3.1.2'
compile group: 'pentaho-kettle', name: 'kettle-core', version: '7.0.0.3-62'
compile group: 'pentaho-kettle', name: 'kettle-sdk-database-plugin', version: '7.0.0.0-25'
compile group: 'pentaho-kettle', name: 'kettle-sdk-step-plugin', version: '7.0.0.0-25'
compile group: 'pentaho-kettle', name: 'kettle-ui-swt', version: '7.0.0.3-62'
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.16'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
full code
import java.util.regex.Pattern;
import be.ibridge.kettle.core.exception.KettleException;
import be.ibridge.kettle.trans.step.StepDataInterface;
import be.ibridge.kettle.trans.step.StepMetaInterface;
import be.ibridge.kettle.core.*;
/**
* @author Michiel
*/
public class JavaExampleCheckRegex {
private Pattern p = null;
private FieldHelper fieldToTest = null;
private FieldHelper outputField = null;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi)
throws KettleException
{
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
// prepare regex and field helpers
if (first){
first = false;
String regexString = getParameter("regex");
p = Pattern.compile(regexString);
fieldToTest = get(Fields.In, getParameter("test_field"));
outputField = get(Fields.Out, "result");
}
r = createOutputRow(r, data.outputRowMeta.size());
// Get the value from an input field
String test_value = fieldToTest.getString(r);
// test for match and write result
if (p.matcher(test_value).matches()){
outputField.setValue(r, Long.valueOf(1));
}
else{
outputField.setValue(r, Long.valueOf(0));
}
// Send the row on to the next step.
putRow(data.outputRowMeta, r);
return true;
}
}
Screenshot of some methods it cannot detect (in red):
Screenshot of some methods that are available in multiple libraries:
EDIT: Manually adding ALL of the Jars from \\data-integration\\lib\\ does not work either.
Did you import the methods in red ?
It is not because the file is on the classpath that the class knows it needs to import them.
That would also fix your multiple library issue, because the import specify the full path name.
import be.ibridge.kettle.core.exception.KettleException;
...
public class JavaExampleCheckRegex{
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.