Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java程序执行flume配置文件?_Java_Flume - Fatal编程技术网

如何使用java程序执行flume配置文件?

如何使用java程序执行flume配置文件?,java,flume,Java,Flume,我有一个flume配置文件filename.conf,当我在终端中执行这个文件时,它工作得很好。但是我尝试使用Runtime.getRuntime().exec函数在java程序中执行相同的文件,但它不起作用 这是我的flume执行命令: /home/path/flume/bin/flume-ng agent --conf-file /home/path/flume/filename.conf --name Agent -Dflume.root.logger=INFO,console 这是我的

我有一个flume配置文件
filename.conf
,当我在终端中执行这个文件时,它工作得很好。但是我尝试使用
Runtime.getRuntime().exec
函数在java程序中执行相同的文件,但它不起作用

这是我的
flume
执行命令:

/home/path/flume/bin/flume-ng agent --conf-file /home/path/flume/filename.conf --name Agent -Dflume.root.logger=INFO,console
这是我的java代码:

Process p;

p = Runtime.getRuntime().exec("/home/path/flume/bin/flume-ng agent --conf-file   /home/path/flume/filename.conf --name TwitterAgent -Dflume.root.logger=INFO,console");

p.waitFor();

BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = "";

while ((line = reader.readLine())!= null) 
{
System.out.println(line);
}

我没有收到任何错误。

Flume提供了一个应用程序类,用于使用Java程序运行conf文件。请查找下面的程序

import org.apache.flume.node.Application;
import org.apache.log4j.BasicConfigurator;

public class flume {
    public static void main(String[] args)
    {
        String[] args1 = new String[] { "agent","-nTwitterAgent","-fflume.conf" };
        BasicConfigurator.configure();
        Application.main(args1);
        System.setProperty("hadoop.home.dir", "/");
   }
}

在应用程序类中,需要提供代理、agentname和flume.conf文件路径。在我的例子中,flume.conf文件仅在我的项目类路径中,因此我刚刚指定为-fflume.conf。如果它位于不同的目录中,则需要在那里指定完整路径。之后,您可以将其作为普通java程序运行。

共享您的java代码和错误消息…Process p;p=Runtime.getRuntime().exec(“/home/path/flume/bin/flume ng agent--conf file/home/path/flume/filename.conf--name TwitterAgent-Dflume.root.logger=INFO,控制台”);p、 waitFor();BufferedReader=新的BufferedReader(新的InputStreamReader(p.getInputStream());字符串行=”;虽然((line=reader.readLine())!=null){System.out.println(line);}我没有收到任何错误。但它不起作用。最好将此作为编辑添加到问题中。我编辑了我的帖子。。。谢谢你的回复。。。你能告诉我解决这个问题的建议吗?使用p.exitValue()查看命令的退出值是多少。该命令的作用是什么?您还可以使用fileutils将关键字动态提供给flume.conf文件。