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?
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):
对我来说有用的是改变使用maven(Intellij)版本并使用我之前安装在我的机器上的最新版本。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.