2016-08-03 43 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