您的位置:

kettle与java(kettle怎么说)

本文目录一览:

如何将kettle 集成到java应用

在Java应用程序中调用Kettle的Transformation

package com.ggd543.kettle.trans

import org.pentaho.di.core.util.EnvUtil

import org.pentaho.di.core.KettleEnvironment

import org.pentaho.di.trans.{Trans, TransMeta}

/**

*

* User: 刘永健

* Date: 12-3-8

* Time: 下午12:14

* To change this template use File | Settings | File Templates.

*/

object TransDemo extends App {

execTrans(args(0)) // ktr文件的全路径

def execTrans(fileName: String) {

KettleEnvironment.init()

EnvUtil.environmentInit();

val transMeta = new TransMeta(fileName)

val trans = new Trans(transMeta)

trans.execute(null) // you can pass arguments instead of null

trans.waitUntilFinished();

if (trans.getErrors 0) {

throw new RuntimeException("There were errors during transformation execution")

}

}

}

?xml version="1.0" encoding="UTF-8"?

project xmlns=""

xmlns:xsi=""

xsi:schemaLocation=" "

modelVersion4.0.0/modelVersion

groupIdkettledemo/groupId

artifactIdkettledemo/artifactId

version1.0/version

dependencies

!-- Test --

dependency

groupIdjunit/groupId

artifactIdjunit/artifactId

version4.8.1/version

scopetest/scope

/dependency

dependency

groupIdorg.scala-tools.testing/groupId

artifactIdspecs_2.9.1/artifactId

version1.6.9/version

scopetest/scope

/dependency

dependency

groupIdorg.scalatest/groupId

artifactIdscalatest_2.9.1/artifactId

version1.6.1/version

scopetest/scope

/dependency

dependency

groupIdcom.typesafe.akka/groupId

artifactIdakka-actor/artifactId

version2.0/version

/dependency

dependency

groupIdcom.typesafe.akka/groupId

artifactIdakka-testkit/artifactId

version2.0/version

/dependency

/dependencies

build

plugins

plugin

groupIdorg.apache.maven.plugins/groupId

artifactIdmaven-compiler-plugin/artifactId

configuration

source1.6/source

target1.6/target

encodingUTF-8/encoding

/configuration

/plugin

/plugins

/build

profiles

profile

idpentaho/id

activation

activeByDefaulttrue/activeByDefault

/activation

properties

pentaho.kettle.version4.2.1.1/pentaho.kettle.version

/properties

dependencies

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-core/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-db/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-engine/artifactId

version${pentaho.kettle.version}/version

/dependency

dependency

groupIdpentaho/groupId

artifactIdpentaho-hdfs-vfs/artifactId

version1.0.1/version

/dependency

dependency

groupIdlog4j/groupId

artifactIdlog4j/artifactId

version1.2.16/version

/dependency

dependency

groupIdpentaho-kettle/groupId

artifactIdkettle-test/artifactId

version${pentaho.kettle.version}/version

scopetest/scope

/dependency

/dependencies

repositories

repository

idpentaho/id

namePentaho Repository/name

url;/url

/repository

/repositories

/profile

profile

idscala/id

activation

activeByDefaulttrue/activeByDefault

/activation

properties

scala.version2.9.1/scala.version

/properties

repositories

repository

idtypesafe/id

nameTypesafe Repository/name

url;/url

/repository

/repositories

dependencies

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-compiler/artifactId

version${scala.version}/version

scopecompile/scope

/dependency

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-library/artifactId

version${scala.version}/version

/dependency

dependency

groupIdorg.scala-lang/groupId

artifactIdscala-swing/artifactId

version${scala.version}/version

/dependency

/dependencies

build

plugins

plugin

groupIdorg.scala-tools/groupId

artifactIdmaven-scala-plugin/artifactId

executions

execution

goals

goalcompile/goal

goaltestCompile/goal

/goals

/execution

/executions

/plugin

/plugins

/build

/profile

/profiles

/project

java 怎么设置kettle数据库

java调用kettle数据库类型资源库中的ktr

此问题在1个月前或许已经接触,单是一直木有怎么用到,就被耽搁至今;问题的解决要来源于网络,其实我还想说问题的解决更多的是要靠我们自己的思想,不过多的言情,我们接下来直接进入主题吧!

环境:kettle-spoon 4.2.0,oracle11g,myeclipse6.5,sqlserver2008

前提:在kettle图形界面spoon里面已经做好了一个ktr转换模型,此时我的ktr信息如下图:

Step1:在myeclipse创建project,导入kettle集成所需要的包

Step2:重点解析与code源码

//定义ktr名字

private static String transName = "test1";

//初始化kettle环境

KettleEnvironment.init();

//创建资源库对象,此时的对象还是一个空对象

KettleDatabaseRepository repository = new KettleDatabaseRepository();

//创建资源库数据库对象,类似我们在spoon里面创建资源库

DatabaseMeta dataMeta =

new DatabaseMeta("enfo_bi","Oracle","Native","ip","sid","port","username","password");

//资源库元对象,名称参数,id参数,描述等可以随便定义

KettleDatabaseRepositoryMeta kettleDatabaseMeta =

new KettleDatabaseRepositoryMeta("enfo_bi", "enfo_bi", "king description",dataMeta);

//给资源库赋值

repository.init(kettleDatabaseMeta);

//连接资源库

repository.connect("admin","admin");

//根据变量查找到模型所在的目录对象

RepositoryDirectoryInterface directory = repository.findDirectory("/enfo_worker/wxj");

//创建ktr元对象

TransMeta transformationMeta = ((Repository) repository).loadTransformation(transName, directory, null, true, null ) ;

//创建ktr

Trans trans = new Trans(transformationMeta);

//执行ktr

trans.execute(null);

//等待执行完毕

trans.waitUntilFinished();

上面的两个步骤才可以确定是资源库中的那个路径下的ktr和我们用命令执行一样的-dir ,-tran -job

附上源码:

package kettle;

import org.pentaho.di.core.KettleEnvironment;

import org.pentaho.di.core.database.DatabaseMeta;

import org.pentaho.di.core.exception.KettleException;

import org.pentaho.di.repository.Repository;

import org.pentaho.di.repository.RepositoryDirectoryInterface;

import org.pentaho.di.repository.kdr.KettleDatabaseRepository;

import org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta;

import org.pentaho.di.trans.Trans;

import org.pentaho.di.trans.TransMeta;

/**

* pTitle: java调用kettle4.2数据库型资料库中的转换/p

* pDescription: /p

* pCopyright: Copyright () 2012/p

*/

public class ExecuteDataBaseRepTran {

private static String transName = "test1";

public static void main(String[] args) {

try {

//初始化kettle环境

KettleEnvironment.init();

//创建资源库对象,此时的对象还是一个空对象

KettleDatabaseRepository repository = new KettleDatabaseRepository();

//创建资源库数据库对象,类似我们在spoon里面创建资源库

DatabaseMeta dataMeta =

new DatabaseMeta("enfo_bi","Oracle","Native","ip","sid","port","username","password");

//资源库元对象,名称参数,id参数,描述等可以随便定义

KettleDatabaseRepositoryMeta kettleDatabaseMeta =

new KettleDatabaseRepositoryMeta("enfo_bi", "enfo_bi", "king description",dataMeta);

//给资源库赋值

repository.init(kettleDatabaseMeta);

//连接资源库

repository.connect("admin","admin");

//根据变量查找到模型所在的目录对象,此步骤很重要。

RepositoryDirectoryInterface directory = repository.findDirectory("/enfo_worker/wxj");

//创建ktr元对象

TransMeta transformationMeta = ((Repository) repository).loadTransformation(transName, directory, null, true, null ) ;

//创建ktr

Trans trans = new Trans(transformationMeta);

//执行ktr

trans.execute(null);

//等待执行完毕

trans.waitUntilFinished();

if(trans.getErrors()0)

{

System.err.println("Transformation run Failure!");

}

else

{

System.out.println("Transformation run successfully!");

}

} catch (KettleException e) {

e.printStackTrace();

}

}

}

如何将JAVA程序集成到KETTLE中

在Java应用程序中调用Kettle的Transformation

package com.ggd543.kettle.trans

import org.pentaho.di.core.util.EnvUtil

import org.pentaho.di.core.KettleEnvironment

import org.pentaho.di.trans.{Trans, TransMeta}

/**

*

* User: 刘永健

* Date: 12-3-8

* Time: 下午12:14

* To change this template use File | Settings | File Templates.

*/

object TransDemo extends App {

execTrans(args(0)) // ktr文件的全路径

def execTrans(fileName: String) {

KettleEnvironment.init()

EnvUtil.environmentInit();

val transMeta = new TransMeta(fileName)

val trans = new Trans(transMeta)

trans.execute(null) // you can pass arguments instead of null

trans.waitUntilFinished();

if (trans.getErrors 0) {

throw new RuntimeException("There were errors during transformation execution")

}

}

}