Java 执行 datax

import com.alibaba.datax.core.Engine;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author: 
 * @descripition:
 * @Date: 2021/7/27 15:35
 * @Version 1.0
 */
public class DataxTest {
    /**
     * @Author
     * @Description java 代码集成
     * @param: args
     * @Version  1.0
     * @Date 2021/7/27 16:00
     */
    public static void main(String[] args){
        System.setProperty("datax.home", "D:\\project\\datax_v2\\datax");
        String[] datxArgs = {"-job", "D:\\project\\datax_v2\\\\datax\\job\\job_01.json", "-mode", "standalone", "-jobid", "-1"};
        try {
            Engine.entry(datxArgs);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    /**
     * @Author 
     * @Description java 执行python任务
     * @param:
     * @Version  1.0
     * @Date 2021/7/27 16:01
     */
    @Test
    public void method() throws IOException, InterruptedException {
        System.out.println("start");
        String windwcmd = "cmd /c python D:\\project\\datax_v2\\datax\\bin\\datax.py  D:\\project\\datax_v2\\datax\\job\\job_01.json";
        System.out.println(windwcmd);
        Process process = Runtime.getRuntime().exec(windwcmd);
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = in.readLine()) != null){
            System.out.println(line);
        }
        in.close();
        process.waitFor();
        System.out.println("end");
    }

}

 pom

<dependency>
            <groupId>com.alibaba.datax</groupId>
            <artifactId>datax-core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.datax</groupId>
            <artifactId>streamreader</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.datax</groupId>
            <artifactId>streamwriter</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
jar包位置在datax  安装目录 plugin 文件夹里

  

 

posted @ 2021-07-27 16:05  涂小二  阅读(1212)  评论(0编辑  收藏  举报