2016-08-03 78 views
0

我想導入一個jar文件,並使用它的依賴到一個Maven項目。 我想導入的jar文件本身就是另一個Maven項目,並且包含了它的所有依賴關係。如何使用jar文件中的依賴關係?

我設法導入我的jar文件並使用java代碼(從Maven項目jar文件的src/main中的包中),但導入mt jar文件的項目仍然無法識別jar的依賴項。

例如,我想導入org.json.JSONObject(他們在jar文件中定義了依賴關係),但是存在編譯錯誤。

有沒有辦法做我想要的或任何其他解決方案?

謝謝!

(對不起,解釋不好的水平,我是法國人,而且非常難以形成我詳細解釋我的問題)

編輯

這裏是從我的罐子我POM的樣本文件:

<!-- One of the dependency I want to use --> 
    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
     <version>20160212</version> 
     <scope>test</scope> 
    </dependency> 

<!-- The plugin I used to create my jar file with dependencies --> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

然後我包括使用「在項目」庫中的jar文件這裏說明:http://charlie.cu.cc/2012/06/how-add-external-libraries-maven/

錯誤消息是編譯錯誤信息說org.json.JSONObject無法識別: package org.json does not exist

+1

顯示POM和錯誤信息 – Jens

+0

刪除'測試'? –

回答

1

您只需爲測試範圍添加JSON庫。

刪除範圍,錯誤應該消失。

<!-- One of the dependency I want to use --> 

<dependency> 
    <groupId>org.json</groupId> 
    <artifactId>json</artifactId> 
    <version>20160212</version> 
</dependency> 
+0

不客氣 – Jens