We have an organization reports portal for which we use Pentaho. Now the catch is, we need to define one single java Jar in which Pentaho + java files + sql, all are there.
I'm able to execute SQL via Pentaho but I need to execute a class in the same jar via pentaho. This can be done via user Defined Java Class. But how to do it? How to directly import java class in the KTR --> UserDefinedJavaClass.
Folder Structure in jar:
MainJar
|-testJob.kjb
|-testTransformer.ktr
|-com.mainTest.HelloWorld.class
How to call HelloWorld.class from test.ktr?
I haven't been able to get it working with User Defined Java Class step but using the Javascript step instead. You need to copy the JAR to pentaho /lib or /libext folder first. Then in the modified javascript step I just called the class. Here is my step 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);
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.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.