[英]How do I make IntelliJ IDEA automatically extract a dependency to the artifact jar?
Let's say I'm adding the following dependency to my pom.xml: 假设我要在我的pom.xml中添加以下依赖项:
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
I can now use the Ini class as expected, but if I try to build the jar and run it, it will give me a "noclassdeffounderror" error. 现在,我可以按预期使用Ini类,但是如果我尝试构建jar并运行它,它将给我一个“ noclassdeffounderror”错误。 When I check the content of the jar, it does not contain org/ini4j.
当我检查jar的内容时,它不包含org / ini4j。
I was able to fix this by going into File -> Project Structure -> Artifacts 我可以通过进入File-> Project Structure-> Artifacts来解决此问题
If I want to add another dependency, I'll have to do this every time, which is quite tedious (I didn't need to do this on NetBeans). 如果要添加另一个依赖关系,则每次都必须这样做,这很繁琐(我不需要在NetBeans上这样做)。 I then tried to use the following plugins (which I used on NetBeans) to have Maven create a jar with dependencies automatically.
然后,我尝试使用以下插件(我在NetBeans上使用了这些插件)使Maven自动创建具有依赖项的jar。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
On NetBeans, this automatically adds all dependencies to the jar file, but it doesn't do anything on IntelliJ IDEA. 在NetBeans上,这会自动将所有依赖项添加到jar文件中,但在IntelliJ IDEA上却不执行任何操作。 I have no idea what I'm doing anymore;
我不知道我在做什么。 nothing works.
没有任何效果。 How can I make IntelliJ IDEA automatically extract a dependency into the output root?
如何使IntelliJ IDEA自动将依赖项提取到输出根目录中?
Dose your intellij use the same version on maven that your Netbeans uses? 您的intellij是否在Maven上使用与Netbeans使用的相同版本? if it checks fine, try another plugin for making a fat jar such as the folowing:
如果检查正常,请尝试使用另一个插件来制作胖罐子,例如:
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.