[英]Pentaho start a java program inside the same jar
We have an organization reports portal for which we use Pentaho. 我们有一个使用Pentaho的组织报告门户。 Now the catch is, we need to define one single java Jar in which Pentaho + java files + sql, all are there.
现在要抓住的是,我们需要定义一个单个的Java Jar,其中包含Pentaho + Java文件+ sql。
I'm able to execute SQL via Pentaho but I need to execute a class in the same jar via pentaho. 我可以通过Pentaho执行SQL,但是我需要通过pentaho在同一jar中执行一个类。 This can be done via user Defined Java Class.
这可以通过用户定义的Java类来完成。 But how to do it?
但是怎么做呢? How to directly import java class in the KTR --> UserDefinedJavaClass.
如何在KTR-> UserDefinedJavaClass中直接导入Java类。
Folder Structure in jar: jar中的文件夹结构:
MainJar MainJar
|-testJob.kjb | -testJob.kjb
|-testTransformer.ktr | -testTransformer.ktr
|-com.mainTest.HelloWorld.class | -com.mainTest.HelloWorld.class
How to call HelloWorld.class from test.ktr? 如何从test.ktr调用HelloWorld.class?
I haven't been able to get it working with User Defined Java Class step but using the Javascript step instead. 我无法使其与“用户定义的Java类”步骤一起使用,而是改为使用Javascript步骤。 You need to copy the JAR to pentaho /lib or /libext folder first.
您需要先将JAR复制到pentaho / lib或/ libext文件夹。 Then in the modified javascript step I just called the class.
然后,在经过修改的javascript步骤中,我刚刚调用了该类。 Here is my step XML
这是我的步骤XML
<entry>
<name>JavaScript</name>
<description />
<type>EVAL</type>
<script>
var filename=parent_job.getVariable("filename","");
var filenameClean=filename+"_clean";
package.CsvCleaner(filename,filenameClean);
</script>
<parallel>N</parallel>
<draw>Y</draw>
<nr>0</nr>
<xloc>800</xloc>
<yloc>1008</yloc>
</entry>
The important part is package.CsvCleaner(filename,filenameClean);
重要的部分是
package.CsvCleaner(filename,filenameClean);
actually invokes the constructor of the class with the two parameters and I have added my code in the constructor. 实际上使用两个参数调用类的构造函数,并且我在构造函数中添加了代码。 You can also call methods and stuff.
您还可以调用方法和内容。
I guess the User Defined Java is called in a similar way -add the jar to /lib import the class and use it. 我猜以类似的方式调用用户定义的Java-将jar添加到/ lib导入类并使用它。
I have one advise though. 我有一个建议。 In my opinion it is better to leave the JAR with the actual ETL code (and not making it part of pentaho by adding it to /lib or /libext) and execute it using a shell command - something like
java -jar MyProg.jar
Otherwise you will have strange problems: 在我看来,最好让JAR保留实际的ETL代码(并且不要通过将其添加到/ lib或/ libext使其成为pentaho的一部分),并使用shell命令执行它-类似于
java -jar MyProg.jar
否则您将遇到奇怪的问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.