如何从IntelliJ中的java模块生成一个jar,并将依赖项放在一个单独的目录中? [英] How to generate a jar from a java module in IntelliJ with the dependencies placed in a separate directory?

查看:947
本文介绍了如何从IntelliJ中的java模块生成一个jar,并将依赖项放在一个单独的目录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块,我想要创建一个jar。所以,这就是我所做的:

I have a module for which I want a jar to be created. So, here is what I do:


  1. 使用From modules with dependencies ...选项添加jar工件

  2. 在来自库的Jar文件中,我选择复制到输出目录并通过清单链接

  3. 保留所有默认值。

之后,我可以构建jar,并将所有依赖项放在同一目录中。到目前为止一直很好。

After that I can build the jar and all the dependencies would be placed near it in the same directory. So far so good.

现在我希望所有依赖项都放在最终jar附近的一个单独目录中。所以,我重复相同的步骤,但这次我在工件输出布局选项卡中的 节点下创建了一个新目录(使用创建目录按钮)。接下来,我将所有依赖项拖到新文件夹上并应用更改。

Now I wish all the dependencies to be placed in a separate directory near the final jar. So, I repeat the same steps, but this time I create a new directory under the node in the artifact Output Layout tab (using the "Create Directory" button). Next I drag all the dependencies onto the new folder and apply the changes.

从表面上看,一切都很酷 - 依赖项确实放在专用目录中,但MANIFEST.MF文件永远不会更新!它应该通过新目录引用依赖项。截至目前,生成的jar无法运行 - 其依赖关系不可见。

On the surface, everything is cool - the dependencies are indeed placed in the dedicated directory, but the MANIFEST.MF file is never updated! It should reference the dependencies via the new directory. As of now, the produced jar cannot be run - its dependencies are not visible.

这与Eclipse不同,它确保导出项目时清单文件是正确的作为jar。

This is unlike Eclipse, which does make sure the manifest file is correct when exporting a project as jar.

我如何解决这个问题,因为:

How can I workaround this problem, given that:


  • 我希望所有依赖项都在专用文件夹中。

  • 我想使用IntelliJ IDEA

  • 我不想手动编辑清单文件。 / li>
  • I want all the dependencies in a dedicated folder.
  • I want to use IntelliJ IDEA
  • I do not want to edit the manifest file manually.

我正在使用最新下载的IntelliJ IDEA for windows - 11.1.2,build 117.418

I am using the latest download of the IntelliJ IDEA for windows - 11.1.2, build 117.418

谢谢。

推荐答案

目前你必须在工件配置对话框中手动更新类路径,以便它包括子目录:

At the moment you have to update the classpath manually in the artifact configuration dialog so that it includes the subdirectory:

为此问题创建了一个问题请点击,请注明/投票。

这篇关于如何从IntelliJ中的java模块生成一个jar,并将依赖项放在一个单独的目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆