简体   繁体   English

从Pentaho Kettle调用Java库

[英]Calling A Java Library From Pentaho Kettle

I have developed a java class exported into a .jar library that will be called by a Pentaho Kettle 'modified java script'. 我已经开发了一个导出到.jar库的Java类,该库将由Pentaho Kettle“修改后的Java脚本”调用。 The .jar is compiled in Eclipse with JDC Compliance level 1.7. .jar是在Eclipse中使用JDC Compliance 1.7编译的。

When I try to use this class inside a 'modified java script', I get the error: ReferenceError: “xeroCallPackage” is not defined. 当我尝试在“修改后的Java脚本”中使用此类时,出现错误:ReferenceError:未定义“ xeroCallPackage”。 I have tried lots of things without much luck so far. 到目前为止,我已经尝试了很多事情,但运气不佳。

My file xeroCallPackage.jar is in the path with the other *.jar files in Pentaho (..\\data-integration\\lib) 我的文件xeroCallPackage.jar与Pentaho(.. \\ data-integration \\ lib)中其他* .jar文件位于路径中

For info: 有关信息:

The stripped down (for simplicity) java library code is here: 精简后的Java库代码在这里:

package xeroCallPackage;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Map;

public class xeroURLCall {

    public String getResponse(String CONSUMER_KEY, String CONSUMER_PRIVATE_KEY, String URL) throws IOException, OAuthException, URISyntaxException { 

        // stripped out code here
        return response.readBodyAsString();
    }

}

The stripped down Pentaho 'modified java script' is here: 精简的Pentaho“修改后的Java脚本”在这里:

var CONSUMER_KEY = "ffffff";
var CONSUMER_PRIVATE_KEY = "aaaaa";
var URL = "https://gggggggg.rrrrr.wwww";

var ResponseAsString;

ResponseAsString = new     xeroCallPackage.xeroURLCall.getResponse(CONSUMER_KEY,CONSUMER_PRIVATE_KEY,URL);

You will either have to have org as top-most package or prefix the fully qualified name of your class with Packages . 您将不得不把org作为最高级的包,或者在类的全限定名前加上Packages

So in your case the fully qualified name of your class that can be used for calling from Spoon will be Packages.xeroCallPackage.xeroURLCall 因此,在您的情况下,可用于从Spoon调用的类的完全限定名称为Packages.xeroCallPackage.xeroURLCall

Apart from that the supplied JavaScript code won't work (but maybe that's just because of the stripped down code). 除此之外,提供的JavaScript代码不起作用(但这可能只是因为代码减少了)。 You'd have to create a xeroURLCall object first and then call the getResponse method on that object: 您必须先创建一个xeroURLCall对象,然后在该对象上调用getResponse方法:

var call = new Packages.xeroCallPackage.xeroURLCall(...);
var responseAsString = call.getResponse(CONSUMER_KEY,CONSUMER_PRIVATE_KEY,URL);

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

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