maven项目无法自动导入kettle包
在pom.xml中加入如下节点,这个节点指向了他们自己的jar包仓库1
2
3
4
5
6
7
8
9
10<repositories>
<repository>
<id>pentaho-releases</id>
<url>http://repository.pentaho.org/artifactory/repo/</url>
</repository>
<repository>
<id>pentaho-nexus</id>
<url>https://nexus.pentaho.org/content/groups/omni/</url>
</repository>
</repositories>
调用kettle需要使用到的包:
- commons-vfs-20100924-pentaho.jar
- kettle-core-5.4.0.1-130.jar
- kettle-dbdialog-5.4.0.1-130.jar
- kettle-engine-5.4.0.1-130.jar
- pentaho-big-data-plugins-5.4.0.1-130.jar(data-integration\plugins\pentaho-big-data-plugin下)
- kettle-ui-swt-5.4.0.1-130.jar(ui包我暂时没用到)
maven打包项目找不到第三方引入包

然后在maven项目pom.xml中引入依赖如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>5.4.0.1-130</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kettle-core-5.4.0.1-130.jar</systemPath>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>5.4.0.1-130</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kettle-engine-5.4.0.1-130.jar</systemPath>
</dependency>
<dependency>
<groupId>pentaho</groupId>
<artifactId>pentaho-big-data-plugin</artifactId>
<version>5.4.0.1-130</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/pentaho-big-data-plugin-5.4.0.1-130.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.1-20100924</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-vfs-20100924-pentaho.jar</systemPath>
</dependency>
此外还需要在maven plugin中配置如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
<fork>true</fork>
<addResources>true</addResources>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
这时打包就不会报错了。
kettle有些类找不到
kettle3.x版本到kettle4.x及之后版本有一些代码的迁移和变动
StepLoader是我们获取每步转换信息的基础,其主要改动如下:
- StepLoader.findStepPluginWithID(id) –> PluginRegistry.findPluginWithId(StepPluginType.class, id)
- StepPlugin –> PluginInterface
- StepLoader.getStepClass(StepPlugin) –> (StepMetaInterface)PluginRegistry.loadClass(PluginInterface, PluginClassType.MainClassType)
- StepLoader.getStepPluginID(StepMetaInterface) –> PluginRegistry.getPluginId(StepPluginType..class, StepMetaInterface)
- init() –> taken over by PluginRegistry.init() and StepPluginType.searchPlugins()
- getPluginPackages() –> is now available as getPluginPackages(PluginTypeInterface) returning a list of package names
- getPluginInformation() –> getPluginInformation(PluginTypeInterface) returning a RowBuffer object
JobEntryLoader同样是作业启动的基础,其主要改动如下: - JobEntryLoader.findJobEntriesWithDescription(String) –> PluginRegistry.findPluginWithName(StepPluginType..class, description)
- JobPlugin (also with a wrong name!) –> PluginInterface
- JobEntryLoader.getStepClass(StepPlugin) –> (JobEntryInterface)PluginRegistry.loadClass(PluginInterface, PluginClassType.MainClassType)
- JobEntryLoader.getJobEntryPluginID(JobEntryInterface) –> PluginRegistry.getPluginId(JobEntryPluginType.getInstance(), JobEntryInterface)
- init(): taken over by PluginRegistry.init() and JobEntryPluginType.searchPlugins()
使用java执行kettle
1.通过文件方式执行转换
1 | public static void runTransfer(String[] params, String ktrPath) { |
2.通过文件方式执行job
1 | public static void runJob(Map<String,String> maps, String jobPath) { |
3.执行资源库的中的转换
可以将转换文件存储到资源库,通过程序进行调用1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22public static void runWithDb() throws KettleException{
KettleEnvironment.init();
//创建DB资源库
KettleDatabaseRepository repository=new KettleDatabaseRepository();
DatabaseMeta databaseMeta=new DatabaseMeta("kettle","mysql","jdbc","localhost","kettle","3306","root","root");
//选择资源库
KettleDatabaseRepositoryMeta kettleDatabaseRepositoryMeta=new KettleDatabaseRepositoryMeta("kettle","kettle","Transformation description",databaseMeta);
repository.init(kettleDatabaseRepositoryMeta);
//连接资源库
repository.connect("admin","admin");
RepositoryDirectoryInterface directoryInterface=repository.loadRepositoryDirectoryTree();
//选择转换
TransMeta transMeta=repository.loadTransformation("demo1",directoryInterface,null,true,null);
Trans trans=new Trans(transMeta);
trans.execute(null);
trans.waitUntilFinished();//等待直到数据结束
if(trans.getErrors()>0){
System.out.println("transformation error");
}else{
System.out.println("transformation successfully");
}
}
kettle二次开发实现转换的web接口
1 | //运行作业 |
其中TransBuilder是自己写的生成转换的类,主要实现了表输入->插入更新功能。
1 | public class TransBuilder { |
最后附上kettle官方文档