简体   繁体   English

如何使IntelliJ IDEA自动将依赖项提取到工件jar?

[英]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.

相关问题 如何在IntelliJ IDEA的JAR工件中正确包含资源文件夹? - How do you properly include a resource folder in a JAR artifact in IntelliJ IDEA? 如何在IntelliJ IDEA中为Spring Boot项目构建jar工件 - How to build the jar artifact for a Spring Boot project in IntelliJ IDEA IntelliJ IDEA:如何将maven依赖项放入构建工件的正确位置 - IntelliJ IDEA: how to put maven dependency into correct location of builded artifact 如何将.jar文件添加到IntelliJ IDEA Java项目中? - How do I add a .jar file into an IntelliJ IDEA Java project? 如何解决 IntelliJ IDEA 中 Java 文件的依赖冲突? - How do I resolve dependency conflict for a Java file in IntelliJ IDEA? 将外部库添加到 IntelliJ IDEA 中的工件 jar - Adding external library to artifact jar in IntelliJ IDEA IntelliJ IDEA-缺少工件中的MySQL(JAR) - IntelliJ IDEA - mysql in artifact (JAR) missing 如何从 Intellij 创意项目制作可执行文件? - How do I make an executable file from an intellij idea project? Intellij Idea遵循JAR /图书馆依赖链 - Intellij Idea Follow JAR/library Dependency Chain 从 Intellij IDEA 内部构建时如何在工件 JAR 中包含 slf4j-simple - How to include slf4j-simple in the artifact JAR when build from inside Intellij IDEA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM