2017-04-11 1 views
0

bazel 빌드를 수행하는 동안 인수를 전달하는 방법. 실제로 내 프로그램은 두 개의 인수를 받아 들일 것입니다 .one은 디렉토리이고 다른 하나는 target.csv입니다. 디렉토리 아래에 파일을 가져 와서 csv에 기록해야합니다. 이 작업을 실행 한 후 문제에 직면bazel을 사용하여 빌드하는 동안 인수를 전달하는 방법

bazel build FlinkEx/com/practice:read_files 

-

import java.io.File; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.stream.Collector; 

import org.apache.flink.api.common.functions.FlatMapFunction; 
import org.apache.flink.api.java.DataSet; 
import org.apache.flink.api.java.ExecutionEnvironment; 
import org.apache.flink.api.java.tuple.Tuple1; 
import org.apache.flink.api.java.utils.ParameterTool; 


public class ReadFiles { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) throws Exception { 

    // set up the execution environment 
    try { 
     final ParameterTool params = ParameterTool.fromArgs(args); 
     final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); 

     env.setParallelism(1); // without this multiple files creating 
     env.getConfig().setGlobalJobParameters(params); 

     List<String> paths = new ArrayList<String>(); 
     File dir = new File(params.getRequired("input")); 
     for (File f : dir.listFiles()) { 
     if (f.isFile()) { 
      paths.add(f.getName()); 
     } 
     } 
     DataSet<String> data = env.fromCollection(paths).rebalance(); 
     DataSet<Tuple1<String>> output = data.flatMap(new CSVSplitter()); 
     env.execute(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 
} 
// The operations are defined by specialized classes, here the Splitter class. 


class CSVSplitter implements FlatMapFunction<String, Tuple1<String>> { 

    public void flatMap(String value, Collector<Tuple1<String>> out) throws Exception { 
    out.collect(new Tuple1<String>(value)); 
    } 

} 

내가 노력하고 bazel를 구축 할 수있는 구문.

Worker process sent response with exit code: 1. 
error: wrong number of type arguments; required 3 

내가 인수를 bazel 같은 것을 전달해야 FlinkEx/COM/연습 구축 : read_files에 c :/C : /target.csv

답변

3

당신이 bazel run을 의미합니까?

bazel run FlinkEx/com/practice:read_files -- c:/ c:/target.csv 

또는 직접 바이너리를 실행하고 "일반적으로"인수를 전달할 수 있습니다 : 당신은 --으로 Bazel 호출에서 구분하여 인수를 전달할 수 있습니다

bazel build FlinkEx/com/practice:read_files 
bazel-bin/FlinkEx/com/practice:read_files c:/ c:/target.csv 

을 (이 bazel build을 가정한다 가하고 read_files (bazel-bin)입니다. bazel-genfiles 인 경우 대신 거기에서 실행하십시오.

관련 문제