我创建了一个maven基础项目,它有两个模块,A和B.在A i中,我添加了B作为依赖项,并通过项目结构在B中添加了来自maven的JSoup.
现在我想运行以下代码
A:
public class A {
public static void main(String args[]){
new B().foo();
}
}
B:
public class B {
public void foo() {
System.out.println("B....");//prints B...
new Document("S");// NoClassDefFoundError exception
}
}
当我运行以下代码时,它说:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/nodes/Document
Jsoup只添加到B.iml而不是B.pom文件中:
我可以通过向A添加jsoup依赖来解决这个问题,但我认为这不是一个好主意.
A是否有任何方式可以识别所有B的依赖关系?
根pom:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
xxx
xxx
pom
0.5-SNAPSHOT
A
B
一个人的pom
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xxx
xxx
0.5-SNAPSHOT
4.0.0
A
B的pom:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xxx
xxx
0.5-SNAPSHOT
4.0.0
B