【发布时间】:2016-08-03 17:44:31
【问题描述】:
我正在尝试导入 jar 文件并将其依赖项用于 Maven 项目。 我要导入的 jar 文件本身就是另一个 Maven 项目,包含它的所有依赖项。
我设法导入了我的 jar 文件并使用了 java 代码(来自我在 Maven 项目 jar 文件中的 src/main 中的包),但我导入 mt jar 文件的项目仍然无法识别 jar 的依赖项。
例如,我正在尝试导入 org.json.JSONObject(在 jar 文件中定义了依赖项)但出现编译错误。
有什么方法可以做我想做的事或任何其他解决方案吗?
谢谢!
(对不起,我的解释很糟糕,我是法国人,我很难详细解释我的问题)
编辑
以下是我的 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
【问题讨论】:
-
显示 pom 和错误信息
-
删除
<scope>test</scope>?
标签: java maven jar dependencies