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");


發佈了79 篇原創文章 · 獲贊 19 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章