[英]Kettle compile Jar with dependencies
Pentaho / Kettle:我不是在“用戶定義的Java類”的代碼框中運行代碼,而是嘗試將其編譯為Jar,然后從“用戶定義的Java類”運行jar文件。 我這樣做是因為我的Java項目太大,並且為了增加模塊化。 但是,依賴項存在一些問題。 有些方法在庫中不可用,而有些方法在多個庫中可用。
我正在嘗試編譯的項目的Zip文件: 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也不起作用。
您是否以紅色導入方法?
這不是因為文件知道類需要將其導入到類路徑中。
這也將解決您的多庫問題,因為導入指定了完整路徑名。
import be.ibridge.kettle.core.exception.KettleException;
...
public class JavaExampleCheckRegex{
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.