maven项目打包以及在liunx上运行

maven项目写完之后,需要打包中含有第三方的jar包的

1、在pom.xml 中添加

  <build>
        <defaultGoal>compile</defaultGoal>
               <plugins>  
            <plugin>  
                <artifactId>maven-assembly-plugin</artifactId>  
                <configuration>  
                    <archive>  
                        <manifest>  
                            <mainClass>com.polaris.mongodb.Query</mainClass>  
                        </manifest>  
                    </archive>  
                    <descriptorRefs>  
                        <descriptorRef>jar-with-dependencies</descriptorRef>  
                    </descriptorRefs>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>

其中<mainClass>com.syswin.mongodb.Query</mainClass> 里面的com.syswin.mongodb.Query是你自己的main 方法的主类。


2、cmd打开命令窗口,切换到项目的根目录下运行 mvn assembly:assembly

F:\workspace\mongodb-to-hdfs>mvn assembly:assembly

当出现如下信息时,表示成功。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.550s
[INFO] Finished at: Mon Nov 21 17:27:24 CST 2016
[INFO] Final Memory: 90M/1078M
[INFO] ------------------------------------------------------------------------


编译完之后在 mongodb-to-hdfs\target 下面会生成一个mongodb-to-hdfs-0.0.1-SNAPSHOT-jar-with-dependencies.jar 文件


3、上传mongodb-to-hdfs-0.0.1-SNAPSHOT-jar-with-dependencies.jar到linux,运行

java -jar /home/Java/mongodb-to-hdfs-0.0.1-SNAPSHOT-jar-with-dependencies.jar $a2 $a3 $a4


后面的是需要的参数。(需要的话就加上,不需要的话就去掉)


4、如果你的项目中涉及到hdfs,运行时报如下错:

java.io.IOException: No FileSystem for scheme: hdfs


这是因为:编译后META-INF中的services目录下,有如下的内容:



在编译时,hadoop-common.jar中的services内容打进了最终的jar包中,而hadoop-hdfs.jar包中,services的内容被覆盖了。

在项目中我们使用了hdfs://ip:port的schema,而在生成的最终jar包中,无法找到这个schema的实现。

所以就抛出了:java.io.IOException: No FileSystem for scheme: hdfs
解决方案是,在设置hadoop的配置的时候,显示设置这个类:"org.apache.hadoop.hdfs.DistributedFileSystem:

Configuration conf = new Configuration();
conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值