-1

私はJavaとEclipseの両方の初心者です。Giraph プログラムを作成するために Eclipse を準備する方法を知りたいですか? 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 bookのソース コードに基づいています。

于 2014-10-22T10:28:23.077 に答える