Kettle源码运行环境如下:
windows10
Kettle 9.3.0.2
Java JDK 11
IntelliJ IDEA 2021.2.2 (Community Edition)
Maven 3.8.1(版本不需要太高 )
导入kettle到IDEA
可通过kettle的GIthub地址获取 kettle的克隆连接,或直接下载ZIP压缩包,将kettle导入到IDEA。
配置Maven
打开Preferences - Build、Execution、Deployment - Builder - Maven
配置Maven为自己下载的Maven 3.8.1,配置Maven的Settings.xml文件
kettle的所需依赖包,在国内没有镜像。需要配置(配置来自kettle源码使用说明):
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- This is the recommended settings.xml for development of Hitachi Vantara projects. -->
<!--
If your wish to mirror everything through pentaho-public's repo uncomment bellow. Not recommended
for external developers.
-->
<!--
<mirrors>
<mirror>
<id>pentaho-public</id>
<url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
-->
<localRepository>D:\mavendata-kettle</localRepository>
<!--
Don't forget to add setting-security.xml so that the password get's decrypted
-->
<servers>
<server>
<id>pentaho-public</id>
<username>devreaduser</username>
<password>{zIMyJWfHKfoHiBJAVsAgW4E5BcJzR+nhTtgPy0J+/rs=}</password>
</server>
</servers>
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>pentaho-public</id>
<url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>�����ƹ����ֿ�</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>central-repository</id>
<mirrorOf>*</mirrorOf>
<name>Central Repository</name>
<url>http://central.maven.org/maven2/</url>
</mirror>
</mirrors>
<!--
You might want to tweak the 'updatePolicy' configuration to fit your need on having updated snapshots and
releases. Our recommendation is to set it to 'never' and run maven with the '-U' flag when needed.
-->
<profiles>
<profile>
<id>pentaho</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>pentaho-public</id>
<name>Pentaho Public</name>
<url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>pentaho-public</id>
<name>Pentaho Public</name>
<url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- this lets you call plugins from these groups in their short form -->
<pluginGroups>
<pluginGroup>org.pentaho.maven.plugins</pluginGroup>
<pluginGroup>com.pentaho.maven.plugins</pluginGroup>
<pluginGroup>com.github.spotbugs</pluginGroup>
</pluginGroups>
</settings>
配置完毕后,右击根pom - Maven - Reload project,等待Maven下载依赖
构建项目
依赖下载完毕后,点击IDEA右边Maven,点击“M”图标,运行命令【mvn clean install -DskipTests】,-DskipTests代表跳过测试
打印台出现一下字样,代表build已经完成了
此时到工程目录下的/assemblies/core/client/target地址
可以看到kettle的压缩包pdi-core-ce-9.3.0.0-SNAPSHOT.zip,解压后,可以看到Spoon.bat文件,在控制台执行定位到解压目录,执行【spoon.bat】即可在windows环境下启动kettle客户端。
windows下创建转换验证功能:
把压缩包pdi-core-ce-9.3.0.0-SNAPSHOT.zip和test.ktr文件上传到linux环境,验证在linux上是否能正常访问:
解压zip文件,并跳转到bin可执行文件目录
./pan.sh -file=/usr/local/test.ktr >> /usr/local/kettle.log
(此处需要注意sh的格式,需要将doc格式转化为unix格式;ktr涉及到的mysq操作需要mysqll驱动jar包,要放到lib包下)
查看结果是否符合预期:
结果(与windos下执行结果一样):
在项目中调试kettle步骤:
启动Spoon.java
在以下路径中找到pentaho-kettle-master/ui/src/main/java/org/pentaho/di/ui/spoon/Spoon.java,右击,选择【run ‘Spoon.main()’】,启动它。
初次运行时,会运行失败,接下来按下面操作进行解决。
第一个错误失败截图如下:
java.lang.UnsatisfiedLinkError: Could not load SWT library
解决方法:
修改一下UI 子模块的中的pom.xml文件改成Windows的swt包
<!-- Third-party dependencies -->
<!-- <dependency>-->
<!-- <groupId>org.eclipse.swt</groupId>-->
<!-- <artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.3</version>
</dependency>
修改 file ->Project Structure -> Modules -> kettle-ui-swt -> Dependencies 中将如下图中所示:将windows的swt放在前面,先加载,后面的linux的swt的jar包就不会再加载(这个如果你是在linux系统下的话,就不用修改这些)然后修改 file ->Project Structure -> Modules -> kettle-ui-swt -> Dependencies 中将如下图中所示:将windows的swt放在前面,先加载,后面的linux的swt的jar包就不会再加载
第二个错误:
添加kettle-password-encoder-plugins.xml到/kettle-core/src/main/resources下
第三个错误
java.lang.NoClassDefFoundError: com/google/api/client/json/JsonFactory
点击"Edit Configurations",打开"Run Debug Configurations"界面
VM options:–class-path=“lib” -XstartOnFirstThread
Working directory:后面追加 dist
在源码目录下新建目录 dist,在 dist 目录中新建子目录 lib 将之前编译成功的发布包 zip 中的 ui 目录解压至<源码目录>\dist 中 将之前编译成功的发布包 zip 中的 lib 目录下的以下 4 个 jar 文件拷贝到<源码目录>\lib 中
其中slf4j-nop-1.7.12.jar,需要到远程仓库下载:https://repo1.maven.org/maven2/org/slf4j/slf4j-nop/1.7.12/
第四个错误:
NoSuchMethodError:找不到方法,大多是jar包冲突导致
第五个错误:
找不到spoon.xul
将之前编译成功的发布包 zip 中的 ui 目录解压至对应模块
代码结构分析
kettle-core:kettle的核心模块,包括一些数据处理等。
kettle-dbdialog:kettle数据库连接界面逻辑。
kettle-engine:kettle的引擎,负责执行kettle的具体作业和转换的逻辑,并会调用core模块。
kettle-ui-swt:用户界面模块,包括用户界面显示的xul文件,通过后端代码编写的Dialog以及国际化等。
pdi-assemblies:该模块用于项目的生成,里面主要包括各个工具启动的脚本、静态资源、帮助文档、组件简单的事例(ktr/kjb)、第三方包引用等。
pdi-engine-ext:kettle引擎扩展模块。
pdi-plugins:kettle的核心插件模块,如果我们要自定义组件,可以参考该模块的组件。
integrantion:集成测试模块。