您的位置:首页 > 其它

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

2016-11-21 17:56 281 查看
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");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: