Reputation: 14060
I've made a small library, lets call it lib
. It dependends on another library, sublib
which is available in Maven central:
lib/pom.xml
:
<dependencies>
<dependency>
<groupId>3rdparty</groupId>
<artifactId>sublib</artifactId>
<version>x</version>
</dependency>
</dependencies>
Now I'm trying to use lib
in my project proj
. I've set it as a dependency:
proj/pom.xml
:
<dependencies>
<dependency>
<groupId>mynamespace</groupId>
<artifactId>lib</artifactId>
<version>y</version>
</dependency>
</dependencies>
When I run mvn exec:java -D exec.mainClass=mynamespace.proj.Main
the program runs fine.
However if I run it from IntelliJ, I get the following error:
java.lang.NoClassDefFoundError: 3rdparty/SomeSubLibClass
at mynamespace.SomeLibClass.method(SomeLibClass.java:100)
This seems to indicate that IntelliJ does not load the transitive sublib
dependency. How can I fix this?
Upvotes: 7
Views: 3254
Reputation: 869
I had a similar problem. The below command resolved the problem. It downloaded all the dependency jars into my IDEA project.
mvn -U idea:idea
Upvotes: 1
Reputation: 1
What worked for me was changing from using maven (Intellij) version and using my latest version that was installed on my machine previously.
Upvotes: 0
Reputation: 10322
You can manually right click on the pom.xml
file in the file tree and select maven > reimport
.
Sometimes you'll see a popup saying "Maven projects need to be imported"; you should select Enable Auto-Import
.
This option can be found in Preferences > Maven > Importing > [x] Import Maven projects automatically
(and is unchecked by default):
Upvotes: 7