<legend id='0bAK9'><style id='0bAK9'><dir id='0bAK9'><q id='0bAK9'></q></dir></style></legend>
    <tfoot id='0bAK9'></tfoot>

        • <bdo id='0bAK9'></bdo><ul id='0bAK9'></ul>

        <small id='0bAK9'></small><noframes id='0bAK9'>

        <i id='0bAK9'><tr id='0bAK9'><dt id='0bAK9'><q id='0bAK9'><span id='0bAK9'><b id='0bAK9'><form id='0bAK9'><ins id='0bAK9'></ins><ul id='0bAK9'></ul><sub id='0bAK9'></sub></form><legend id='0bAK9'></legend><bdo id='0bAK9'><pre id='0bAK9'><center id='0bAK9'></center></pre></bdo></b><th id='0bAK9'></th></span></q></dt></tr></i><div id='0bAK9'><tfoot id='0bAK9'></tfoot><dl id='0bAK9'><fieldset id='0bAK9'></fieldset></dl></div>
      1. Intellij Java 2016 &amp;Maven:如何在 JAR 中嵌入依赖项?

        Intellij Java 2016 amp; Maven : how to embed dependencies in JAR?(Intellij Java 2016 amp;Maven:如何在 JAR 中嵌入依赖项?)
        <tfoot id='jnZ59'></tfoot>
        • <bdo id='jnZ59'></bdo><ul id='jnZ59'></ul>
              <i id='jnZ59'><tr id='jnZ59'><dt id='jnZ59'><q id='jnZ59'><span id='jnZ59'><b id='jnZ59'><form id='jnZ59'><ins id='jnZ59'></ins><ul id='jnZ59'></ul><sub id='jnZ59'></sub></form><legend id='jnZ59'></legend><bdo id='jnZ59'><pre id='jnZ59'><center id='jnZ59'></center></pre></bdo></b><th id='jnZ59'></th></span></q></dt></tr></i><div id='jnZ59'><tfoot id='jnZ59'></tfoot><dl id='jnZ59'><fieldset id='jnZ59'></fieldset></dl></div>

                <tbody id='jnZ59'></tbody>

              <small id='jnZ59'></small><noframes id='jnZ59'>

            • <legend id='jnZ59'><style id='jnZ59'><dir id='jnZ59'><q id='jnZ59'></q></dir></style></legend>

                  本文介绍了Intellij Java 2016 &amp;Maven:如何在 JAR 中嵌入依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Intellij Java 2016.2.2 和 Maven 创建一个非常简单的 Java 控制台应用程序.

                  I'm using Intellij Java 2016.2.2 and Maven to create a very simple Java console application.

                  我想添加一个外部库,所以我在 Maven 中添加我的依赖项,如下所示:

                  I want to add an external library, so I add my dependency in Maven like this:

                  <dependency>
                      <groupId>jline</groupId>
                      <artifactId>jline</artifactId>
                      <version>2.12</version>
                  </dependency>
                  

                  当我在 IDE 中运行它时它运行良好,但在外部控制台中运行它却没有(我有以下错误:java.lang.NoClassDefFoundError).

                  It works fine when I run it in the IDE, but not in an external console (I have the following error: java.lang.NoClassDefFoundError).

                  我检查了,由于某种原因,我刚刚生成的 JAR 中没有添加外部 JAR.我也在文件 - >项目结构"中尝试了很多东西,但仍然无法正常工作......

                  I checked and for some reason, the external JAR is not added in the JAR I just generated. I also tried many things in "File -> Project Structure", but still not working...

                  我只想构建包含我的依赖项的 JAR,因此我可以使用以下命令在控制台中简单地运行我的应用程序:

                  I just want to build my JAR with my dependencies in it, so I can simply run my application in a console using:

                  java -jar myproject.jar
                  

                  我该怎么做?感谢您的帮助!

                  How can I do that? Thanks for your help!

                  推荐答案

                  我终于设法用 Intellij Java 生成了这个 JAR,我是这样做的:

                  I finally managed to generate this JAR with Intellij Java, here is how I do:

                  • 在 pom.xml 文件中添加依赖
                  • 转到文件 -> 项目结构 -> 工件 -> 新建 -> JAR -> 来自具有依赖项的模块
                  • 选择主类并点击确定
                  • 在您的项目中,在 src/main 中,创建resources"文件夹
                  • 将META-INF"(其中包含 MANIFEST.MF)文件夹移动到此资源"文件夹中
                  • 转到构建 -> 构建工件以构建 JAR

                  编辑

                  一种更好(更简单)的方法是在 pom.xml 文件中添加以下行:

                  A better (and easier way) to do it is adding the following lines in the pom.xml file :

                  <build>
                      <plugins>
                          <plugin>
                              <artifactId>maven-assembly-plugin</artifactId>
                              <configuration>
                                  <archive>
                                      <manifest>
                                          <mainClass>your.MainClass</mainClass>
                                      </manifest>
                                  </archive>
                                  <descriptorRefs>
                                      <descriptorRef>jar-with-dependencies</descriptorRef>
                                  </descriptorRefs>
                              </configuration>
                              <executions>
                                  <execution>
                                      <id>make-assembly</id>
                                      <phase>package</phase>
                                      <goals>
                                          <goal>single</goal>
                                      </goals>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>
                  

                  然后使用clean"和package"maven 命令.

                  then use the "clean" and "package" maven commands.

                  上面的最后 3 个步骤(关于 MANIFEST.MF)似乎仍然是强制性的.

                  The last 3 steps above (about MANIFEST.MF) still seem to be mandatory.

                  这篇关于Intellij Java 2016 &amp;Maven:如何在 JAR 中嵌入依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tbody id='s33OF'></tbody>
                    <bdo id='s33OF'></bdo><ul id='s33OF'></ul>

                  • <i id='s33OF'><tr id='s33OF'><dt id='s33OF'><q id='s33OF'><span id='s33OF'><b id='s33OF'><form id='s33OF'><ins id='s33OF'></ins><ul id='s33OF'></ul><sub id='s33OF'></sub></form><legend id='s33OF'></legend><bdo id='s33OF'><pre id='s33OF'><center id='s33OF'></center></pre></bdo></b><th id='s33OF'></th></span></q></dt></tr></i><div id='s33OF'><tfoot id='s33OF'></tfoot><dl id='s33OF'><fieldset id='s33OF'></fieldset></dl></div>

                        <tfoot id='s33OF'></tfoot>
                        <legend id='s33OF'><style id='s33OF'><dir id='s33OF'><q id='s33OF'></q></dir></style></legend>

                            <small id='s33OF'></small><noframes id='s33OF'>