I created a basic maven project and has two modules: A and B In A I added B as a dependency, and also added JSoup from maven to B through Project Structure .
Now I want to run the following codes A:
public class A { public static void main(String args[]){ new B().foo(); } }
IN:
public class B { public void foo() { System.out.println("B....");
When I run the following code, it says:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/nodes/Document
Jsoup is only added to the B.iml not B.pom :
<orderEntry type="library" exported="" name="org.jsoup:jsoup:1.8.3" level="project" />
I can solve this problem by adding jsoup dependency to A , but I think this is not a good idea.
Is there a way that A recognizes all the dependencies of B ?
Root root:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" 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"> <modelVersion>4.0.0</modelVersion> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <packaging>pom</packaging> <version>0.5-SNAPSHOT</version> <modules> <module>A</module> <module>B</module> </modules> </project>
A pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" 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"> <parent> <artifactId>xxx</artifactId> <groupId>xxx</groupId> <version>0.5-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>A</artifactId> </project>
B pom:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" 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"> <parent> <artifactId>xxx</artifactId> <groupId>xxx</groupId> <version>0.5-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>B</artifactId> </project>
source share