Calling custom Java classes and JAR files in ODI via Jython or Java BeanShell
Get our e-books Discover the Oracle Data Integrator 11g Repository Data Model and Oracle Data Integrator Snippets and Recipes
First we create a simple Java class that creates and writes to a text file and save it as FileWrite.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.io.*; public class FileWrite { public void writeFile() { FileOutputStream fos; DataOutputStream dos; try { File file= new File("C:\MyFile.txt"); fos = new FileOutputStream(file); dos=new DataOutputStream(fos); dos.writeInt(2333); dos.writeChars("Hello World"); } catch (IOException e) { e.printStackTrace(); } } } |
Next we compile the .java class from the command line
1 |
c:javac FileWrite.java |
Next we create a .jar file from the class
1 |
c:jar cf FileWrite.jar FileWrite.class |
We then copy and paste the .jar archive to the ODI drivers folder
Next we restart the ODI agent.
We can now call methods in this class from either Jython
1 2 3 |
import FileWrite fw=FileWrite() fw.writeFile() |
or we can call it from the Java BeanShell
1 2 3 |
import FileWrite; FileWrite fw = new FileWrite(); fw.writeFile(); |
[big_data_promotion]
If you want to master scripting in ODI get the following books.
Java BeanShell
Scripting in Java: Languages, Frameworks, and Patterns
Jython
The Definitive Guide to Jython: Python for the Java Platform.
Jython Essentials (O’Reilly Scripting)