阿里云Hadoop开发自动打包上传运行maven的pom.xml

本文介绍了一个使用 Maven 和 Ant 自动化部署 Hadoop WordCount 任务的方案。该方案通过 pom.xml 文件配置实现了远程主机上的 jar 包部署及 Hadoop 任务的执行,同时介绍了相关依赖和构建插件的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录的输入与输出:


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>hadoop0</groupId>
    <artifactId>hadoop0</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>hadoop0</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hadoop.version>2.6.0</hadoop.version>
        <jdiff.version>1.0.9</jdiff.version>
        <remote.home>/root</remote.home>
        <remote.host>IP马赛克</remote.host>
        <remote.username>账户马赛克</remote.username>
        <remote.password>密码马赛克</remote.password>
        <bas.dir>./</bas.dir>
        <dist.dir>${bas.dir}/target/</dist.dir>
        <jar.name>WordCount</jar.name>
        <jar.file>${jar.name}.jar</jar.file>
        <remote.dir>${remote.home}</remote.dir>
 
        <main.class>hadoop0.hadoop0.WordCount</main.class>
        <outpath1>/input/wc.txt</outpath1>
        <outpath2>/output/wc4</outpath2>
        <hadoop.conf>-D mapreduce.map.java.opts=-Xmx2048m -D mapreduce.input.fileinputformat.split.minsize=1 -Dmapreduce.input.fileinputformat.split.maxsize=512000000 -D mapred.linerecordreader.maxlength=32768</hadoop.conf>
        <ssh.cmd>source ${remote.home}/.bashrc;/root/hadoop-2.6.0/bin/hadoop jar  ${remote.dir}/${jar.file} ${hadoop.conf} ${outpath1} ${outpath2}</ssh.cmd>
    </properties>
 
    <build>
        <finalName>${jar.name}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>root/</classpathPrefix>
                            <mainClass>${main.class}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!-- //sss -->
            <plugin>
                <inherited>false</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="a-test"
                                description="how to get antrun plugin to work with SCP and SSH">
                                <echo message="Remember to fill empty fields..." />
                                file to be transferred
                                <scp trust="true" failonerror="true" verbose="off" sftp="true"
                                    file="${dist.dir}/${jar.file}"
                                    todir="${remote.username}:${remote.password}@${remote.host}:${remote.dir}/${jar.file}" />
                                calls deploy script
                                <sshexec host="${remote.host}" trust="yes"
                                    username="${remote.username}" password="${remote.password}"
                                    command="bash -c '${ssh.cmd}'" />
 
                                SSH
                                <taskdef name="sshexec"
                                    classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
                                    classpathref="maven.plugin.classpath" />
                                <taskdef name="scp"
                                    classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp">
                                    <classpath refid="maven.plugin.classpath" />
                                </taskdef>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant</groupId>
                        <artifactId>ant-commons-net</artifactId>
                        <version>1.6.5</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant-jsch</artifactId>
                        <version>1.9.1</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins> 
    </build>
 
 
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-ant-tasks</artifactId>
            <version>2.0.9</version>
        </dependency>
    </dependencies>
</project>


本地eclipse运行:

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值