簡體   English   中英

如何在maven中提供參數 - 對於hadoop WordCount

[英]How to give arguments in maven - for hadoop WordCount

我在eclipse中做Hadoop WordCount.java

我將輸入和輸出路徑作為參數。

我試圖將我的hadoop MR從eclipse juno轉換為maven。

我寫了pom.xml。 但是我應該在哪里包含我的參數?

  • input: /home/sree/myfiles/book.txt
  • output: /home/sree/myfiles/wcout

我編輯過的pom.xml

   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>TryMaven</groupId>
    <artifactId>TryMaven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>

        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>org.WordCount</mainClass>

                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <arguments>
                        <argument>-Dinput=${input}</argument>
                        <argument>-Doutput=${output}</argument>
                        <mainClass>org.WordCount</mainClass>
                    </arguments>
                    <mainClass>org.WordCount</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <repositories>

        <repository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-core</artifactId>
            <version>1.2.1</version>
        </dependency>
    </dependencies>


</project>

Maven項目是構建工具,遷移到maven后,您仍然可以像以前一樣運行程序。 這與maven無關。

Java解決方案

您可以在沒有maven的情況下運行WordCount

java -jar target/TryMaven-0.0.1-SNAPSHOT.jar -Dinput=/home/sree/myfiles/book.txt -Doutput=/home/sree/myfiles/wcout

Maven解決方案

對pom.xml的更改

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-Dinput=${input}</argument>
            <argument>-Doutput=${output}</argument>

            <argument>-classpath</argument>
            <classpath/>

            <mainClass>org.WordCount</mainClass>
        </arguments>
    </configuration>
</plugin>

執行命令

mvn exec:exec -Dinput=/home/sree/myfiles/book.txt -Doutput=/home/sree/myfiles/wcout

您可以直接從Eclipse執行此目標!

Run as - > Maven bulid並指定目標exec:exec和所需的參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM