1.全量 打包 datax
mvn clean package -DskipTests assembly:assembly
2.解压target 下的 datax.tar.gz 到自己指定的目录下(此目录就是下面的datax home)
3.调试datax,修改datax 入口类 com.alibaba.datax.core.Engine,指定job文件 (ps:打包的时候需要把args 的赋值和System.setProperty 注释掉)
public static void main(String[] args) throws Exception {
int exitCode = 0;
try {
//datax.tar.gz解压的目录
System.setProperty("datax.home", "/Users/trueland/Documents/soft/datax");
//设置datax的运行脚本信息 这里的最后一个入参 是我自定义的 job.json ,如果这里你没有编写的话,可以使用 job 目录下自带的 job.json
args = new String[]{"-mode", "standalone", "-jobid", "-1", "-job", "/Users/trueland/Documents/soft/datax/job/esreader.json"};
Engine.entry(args);
} catch (Throwable e) {
exitCode = 1;
LOG.error("\n\n经DataX智能分析,该任务最可能的错误原因是:\n" + ExceptionTracker.trace(e));
if (e instanceof DataXException) {
DataXException tempException = (DataXException) e;
ErrorCode errorCode = tempException.getErrorCode();
if (errorCode instanceof FrameworkErrorCode) {
FrameworkErrorCode tempErrorCode = (FrameworkErrorCode) errorCode;
exitCode = tempErrorCode.toExitValue();
}
}
System.exit(exitCode);
}
System.exit(exitCode);
}
4.指定某几个修改的Module 打包(以es reader 为例子,ps 如果报错,缺少依赖则在pl 后面加上需要的依赖)
mvn install -pl common,core,elasticsearchreader -DskipTests
打包完成之后将对应的reader 粘贴出来替换掉datax_home 中对应的reader,此处我的datax home 是在/Users/trueland/Documents/soft/datax。我需要将/Users/trueland/Documents/soft/datax/plugin/reader/elasticseachreader 删除 将项目中 的esreader target/datax/elasticsearchreader 复制到/Users/trueland/Documents/soft/datax/plugin/reader 下即可
5.注意项,datax 运行加载的代码是datax home 下打包好的代码,不是datax 启动项目下的代码。所以修改了代码,要打包好放入datax_home下