在ODI中调用jar包java方法的过程如下:

1、编写Java代码如下

代码写hello world字符串到一个文件。

package odi;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream; public class HelloWorld { public static void Write_File_Windows() throws Exception { // 1、通过File找到一个文件 File file = new File("D:" + File.separator + "temp.txt"); // 2、实例化OutputStream对象 OutputStream out = new FileOutputStream(file); String info = "Hello World!!!"; // 要输出的字符串 byte data[] = info.getBytes();// 将字符串变为字节数组 out.write(data); // 输出内容 out.close(); } public static void Write_File_Linux() throws Exception { // 1、通过File找到一个文件 File file = new File("/home/oracle/temp.txt"); // 2、实例化OutputStream对象 OutputStream out = new FileOutputStream(file); String info = "Hello World!!!"; // 要输出的字符串 byte data[] = info.getBytes();// 将字符串变为字节数组 out.write(data); // 输出内容 out.close(); } }

2、生成Jar包

2.1 方法一 直接导出Jar包

如果引入了其他的jar包,则选择导出Runnable JAR file类型

2.2 方法二 手工编译并打包成jar包

javac 编译  jar打包

>javac HelloWorld.java

>jar cvf HelloWorld.jar odi

 

三、复制生成的jar包到指定的目录

根据执行的逻辑代理的不同,复制jar包到不同的位置

3.1 使用本地Agent执行的时候(以window为例)

方法一:     复制生成的jar包到 C:\Users\<user-name>\AppData\Roaming\odi\oracledi\userlib

方法二:   复制生成的jar包到 E:\ODI12C\Middleware\Oracle_Home\odi\sdk\lib

方法三:     任意路径,但在 C:\Users\<user-name>\AppData\Roaming\odi\oracledi\userlib\additional_path.txt 中指定

; Additional paths file
; You can add here paths to additional libraries
; Examples:
; C:\ java\libs\myjar.jar
; C:\ java\libs\myzip.zip
; C:\java\libs\*.jar will add all jars contained in the C:\java\libs\ directory
; C:\java\libs\**\*.jar will add all jars contained in the C:\java\libs\ directory and subdirectories
D:\*.jar

3.2 使用配置的远程Agent(以Linux为例)

复制jar包到 data/Oracle/Middleware/Oracle_Home/user_projects/domains/odi_dev_domain/lib目录,需要重新启动ODI_Server

3.3 通用办法

复制jar到某个目录,后面在调用的时候使用下面的代码指定该位置。复制jar包到上面位置 ,在调用时无需下面的代码。

linux下

jars = [
"/data/script/HelloWorld.jar"
] for jar in jars:
sys.path.append(jar)

windows下

jars = [
"D:\HelloWorld.jar"
] for jar in jars:
sys.path.append(jar)

建议:开发的时候使用此方法,可以节省重启ODI_Server的时间。并且避免缓存对开发测试造成的影响。等测试优化完成后,可以使用第三种方法。

4、启动ODI,新建过程调用jar

windows下代码

import os
import sys
 
jars = [
"C:\Users\xqzt\AppData\Roaming\odi\oracledi\userlib\HelloWorld.jar"
] for jar in jars:
sys.path.append(jar)
from odi import HelloWorld

hw=HelloWorld()
hw.Write_File_Windows()

linux下代码

import os
import sys jars = [
"/home/oracle/.odi/oracledi/userlib/HelloWorld.jar"
] for jar in jars:
sys.path.append(jar) from odi import HelloWorld hw=HelloWorld()
hw.Write_File_Linux()

4、运行并验证过程

参考:

http://karanbalkar.com/2013/06/tutorial-33-using-custom-java-code-in-odi/

http://shrikantdhagefmw.blogspot.com/2014/05/invoking-jar-in-oracle-data-integrator.html

http://askankit.blogspot.com/2010/09/call-java-jar-methods-from-odi.html

Using Custom Java code in ODI的更多相关文章

  1. Write Custom Java to Create LZO Files

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LZO LanguageManual LZO     Skip to e ...

  2. Java语言编码规范(Java Code Conventions)

    Java语言编码规范(Java Code Conventions) 名称 Java语言编码规范(Java Code Conventions) 译者 晨光(Morning) 简介 本文档讲述了Java语 ...

  3. java code to byte code--partone--reference

    Understanding how Java code is compiled into byte code and executed on a Java Virtual Machine (JVM) ...

  4. [转]Java Code Examples for android.util.JsonReader

    [转]Java Code Examples for android.util.JsonReader The following are top voted examples for showing h ...

  5. SQL to Java code for Elasticsearch

    Elasticsearch虽然定位为Search Engine,但是因其可以持久化数据,很多时候,我们把Elasticsearch当成Database用,但是Elasticsearch不支持SQL,就 ...

  6. JUnit单元测试教程(翻译自Java Code Geeks)

    JUnit单元测试教程--终极指南 JUnit单元测试教程终极指南 说明 单元测试简介 1 什么是单元测试 2 测试覆盖 3 Java中的单元测试 JUnit简介 1 使用Eclipse实现简单JUn ...

  7. Java Code Style

    近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...

  8. 玩转Eclipse — 自动代码生成的Java Code Template

    文章转载地址:点击打开链接 当代码写到一定程度之后,就会发现很多代码都被重复地敲了N多遍,甚至毫不夸张地说:闭着眼睛都能敲出来.大量地敲这些重复地代码,除了锻炼敲键盘的速度,基本上没有其他益处,但是长 ...

  9. Use formatter to format your JAVA code

    In order to make the codes looks unified and make it easy to understand, it's better to use the same ...

随机推荐

  1. Lua date转秒数

    之前写过一篇关于把秒转换成指定的日期格式 Lua date format   接到一个需求,需要从配置文件中读取活动显示时间段:startDate ~ endDate(格式为:yyyy-mm-dd H ...

  2. Netty 4.0.0.CR6 发布,高性能网络服务框架

    Netty 4.0 发布第 6 个 RC 版本,该版本值得关注的改进有: SslHandler and JZlibEncoder now works correctly. (#1475 and #14 ...

  3. iOS測试——置换測试: Mock, Stub 和其它

    文章地址:http://ryantang.me/blog/2014/08/21/test-doubles/

  4. Maven 入门指南

    为什么要用 Maven? Maven 主要帮助用户完成以下 3 个方面的工作: 生命周期管理,便捷的构建过程: 依赖管理,方便引入所需依赖 Jar 包: 仓库管理,提供统一管理所有 Jar 包的工具: ...

  5. 如何让我domain里的机器都跟domain controller的时间保持一致?

    貌似是应该先在PDC上设一个时间源服务器, 然后, 再让domain里所有的机器都去与PDC去sync时间即可. 可是笔者的环境里, 怎么都配不同, 我觉得可能是实验室的网络有什么特别的设置吧. 不管 ...

  6. ThinkPHP3.2.3使用分页

    首先要搞清楚的就是ThinkPHP3.2.3的分页类已经被移到了Think\Page.class.php,这是跟以前的版本有些不一样的,使用起来还是跟以前版本差不多,但是默认的效果不敢恭维,所以最好是 ...

  7. 代码提示级别设置 inspection

    配置文件 profile [ˈproʊfaɪl] n.侧面; 外形,轮廓; 人物简介; vt.描-的轮廓; 给-画侧面图; inspection [ɪnˈspɛkʃən] n.检验; 检查; 视察; ...

  8. eclipse 创建普通maven项目

  9. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十二)VMW安装四台CentOS,并实现本机与它们能交互,虚拟机内部实现可以上网。

    Centos7出现异常:Failed to start LSB: Bring up/down networking. 按照<Kafka:ZK+Kafka+Spark Streaming集群环境搭 ...

  10. Downloading jQuery 3.2.1

    Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompresse ...