我有一个Flume配置文件 filename.conf
,当我在终端执行这个文件时,它工作得很好。但是我尝试在java程序中使用 Runtime.getRuntime().exec
功能不起作用。
这是我的 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);
}
我没有得到任何错误。
1条答案
按热度按时间cbeh67ev1#
flume提供了一个应用程序类来使用java程序运行conf文件。请查找以下程序。
在应用程序类中,需要提供代理、agentname和flume.conf文件路径。在我的例子中,flume.conf文件只在我的项目类路径中,所以我刚刚指定为-fflume.conf。如果它在不同的目录中,则需要在那里指定完整路径。在此之后,您可以将其作为普通java程序本身运行。