描述
我有3个节目。
我的主程序名为 Main
. 那我有两个 jar
文件: Utils1
以及 Utils2
. Utils2
用于 Utils1
. 所以我把它和maven一起导入了
Utils1 pom.xml
.
<dependency>
<groupId>org.group.project</groupId> // random text
<artifactId>Project</artifactId> // random text
<version>1.0.0</version> // random version
<scope>system</scope>
<systemPath>${basedir}/Utils2.jar</systemPath>
</dependency>
``` `Utils2` 包含名为 `custompack` ,一个名为 `MyMaths` 以及一个名为 `MyAddition` . `Utils1` 包含名为 `CustomMaths` 以及一个名为 `CustomAddition` . `CustomAddition` 呼叫 `Utils2.custompack.MyMaths.MyAddition` .
所以我们的密码 `Utils1` 看起来像:
public int CustomAddition (int item1, int item2) {
MyMaths mymaths = new MyMaths();
return mymaths.MyAddition(item1, item2);
}
问题
当我使用 `CustomAddition` 在我的 `Main` 课程:
java.lang.noclassdeffounderror:自定义包/mymaths
问题
我想 `Utils2` jar在中未正确导入 `Utils1` jar。
你知道吗?谢谢您。
1条答案
按热度按时间ia2d9nvy1#
我假设utils1和utils2都是定制构建jar。
基于maven的工作原理,
您应该首先构建utils1项目,该项目应该将artifact/jar复制到maven repo(默认值为c:\users[account].m2\repository,否则请检查c:\users[account].m2\settings.xml以防重写)。
构建utils2项目并运行利用utils2类的主程序
另外,由于这些是自定义模块,您应该如下所示添加依赖项-
当您在构建/执行过程中有一个在maven repo中不可用的jar并且需要从不同的位置提取时,应该使用下面的内容
看到了吗https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html