-1

我是 java 和 Eclipse 的初学者。我想知道如何准备 Eclipse 来制作 Giraph 程序?我已经设置了 Giraph 并且它正在工作。有没有办法在 Giraph 上从 Eclipse 运行书面程序?

谢谢

4

2 回答 2

1

是的,可以在没有 Hadoop 集群的情况下从单个 Java 应用程序运行 Giraph。

  1. 你的主要课程是这样的:

    public class GiraphHelloWorld extends BasicComputation<IntWritable, IntWritable, NullWritable, NullWritable> {
    
        @Override
        public void compute(Vertex<IntWritable, IntWritable, NullWritable> vertex,
                Iterable<NullWritable> messages) {
            System.out.print("Hello world from : " + vertex.getId().toString()
                    + " friends are:");
            for (Edge<IntWritable, NullWritable> e : vertex.getEdges()) {
                System.out.print(" " + e.getTargetVertexId());
            }
            System.out.println("");
            vertex.voteToHalt();
        }
        public static void main(String[] args) throws Exception {
            System.exit(ToolRunner.run(new GiraphRunner(), args));
        }
    }
    
  2. 您的入门课程是这样的:

    public class TestGiraphApp {
        final static String[] graphSeed = new String[] { "seed\t0" }; 
    
        @Test
        public void testNumberOfVertices() throws Exception {
            GiraphConfiguration conf = new GiraphConfiguration();
            conf.setComputationClass(GiraphHelloWorld.class);
            conf.setVertexInputFormatClass(IntIntNullTextInputFormat.class);
            conf.setVertexOutputFormatClass(AdjacencyListTextVertexOutputFormat.class);
            Iterable<String> results = InternalVertexRunner.run(conf, graphSeed);
        }
    }
    
  3. pom.xml文件必须包含 Giraph 和 Hadoop:

    <dependency>
        <groupId>org.apache.giraph</groupId>                             
        <artifactId>giraph-core</artifactId>
        version>1.1.0</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.hadoop</groupId>                             
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
    </dependency>
    

该示例基于Practical Graph Analytics with Apache Giraph一书的源代码。

于 2014-10-22T10:28:23.077 回答
0

1. "... how to prepare Eclipse to make a Giraph program?":

I tried it ~7 months ago, without any success. I ended up using the Community Edition of IntelliJ IDEA - with that it works smoothly. You can than just clone the giraph repository and start working with the examples, as well as creating your own examples. This way you don't need to set up a maven config file, ...

2. "... is there a way to run a written program from Eclipse on Giraph?"

If you have added your code to the examples, you can just rebuild the whole giraph project with mvn clean install -DskipTests and run that giraph version. Otherwise you need to build your own jar file to run it with giraph. There is no way to just press the "run" button and have the whole debug experience of IntelliJ (or Eclipse)

于 2014-05-26T22:10:10.173 回答