简体   繁体   English

Kettle编译具有依赖项的Jar

[英]Kettle compile Jar with dependencies

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". Pentaho / Kettle:我不是在“用户定义的Java类”的代码框中运行代码,而是尝试将其编译为Jar,然后从“用户定义的Java类”运行jar文件。 I do this because my Java projects are too big, and in order to increase modularity. 我这样做是因为我的Java项目太大,并且为了增加模块化。 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 . 我正在尝试编译的项目的Zip文件: https : //drive.google.com/file/d/1H-RGGvH-h3zvLnF3qIVVIHnnB4vtwKvN/view?usp=sharing

Code of the Gradle dependencies I am using: 我正在使用的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'
}

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. 编辑:从\\ data-integration \\ lib \\手动添加所有Jars也不起作用。

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{
...
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM