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\中的所有Jars也不起作用。
发布于 2018-11-12 23:00:13
你导入红色的方法了吗?
并不是因为文件在类路径上,类才知道需要导入它们。
这还可以解决多个库问题,因为导入指定了完整路径名。
import be.ibridge.kettle.core.exception.KettleException;
...
public class JavaExampleCheckRegex{
...
} https://stackoverflow.com/questions/53261059
复制相似问题