Pentaho / Kettle:我不是在“用户定义的Java类”的代码框中运行代码,而是尝试将其编译为Jar,然后从“用户定义的Java类”运行jar文件。我这样做是因为我的Java项目太大,并且为了增加模块化。但是,依赖项存在一些问题。这些方法在库中不可用,而某些方法在多个库中可用。
我要编译的项目的压缩文件:https://drive.google.com/file/d/1H-RGGvH-h3zvLnF3qIVVIHnnB4vtwKvN/view?usp=sharing。
我正在使用的Gradle依赖项代码:
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'
}
完整代码
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;
}
}
编辑:从\ data-integration \ lib \手动添加所有Jar也不起作用。
答案 0 :(得分:0)
您是否以红色导入了方法?
不是因为文件位于类路径上,类才知道需要导入它们。
这也可以解决您的多库问题,因为导入时会指定完整路径名。
import be.ibridge.kettle.core.exception.KettleException;
...
public class JavaExampleCheckRegex{
...
}