简体   繁体   English

在 IntelliJ IDEA 中将所有子目录 JAR 添加到依赖项中

[英]Add all sub-directories JARs into dependencies in IntelliJ IDEA

I have a folder with multiple sub-directories, which all have a JAR file in each of them.我有一个包含多个子目录的文件夹,每个子目录中都有一个 JAR 文件。 This is a simplified structure of the files:这是文件的简化结构:

lib/
|
|__lib1/
|  |_version1/
|  | |_lib1-1.0.jar
|  |_version2/
|  | |_lib1-2.0.jar
|
|__lib2/
|  |_version1/
|  | |_lib2-1.0.jar
|  |_version2/
|  | |_lib2-2.0.jar

Now, I would like to add all of the JARs recursively into the dependencies list inside of the Project Strucutre (in IntelliJ IDEA 14).现在,我想将所有 JAR 递归添加到 Project Strucutre 内的依赖项列表中(在 IntelliJ IDEA 14 中)。

Is there a quick way of achieving this without having to expand all directories and select the artifacts manually?有没有一种快速的方法来实现这一点,而无需展开所有目录并手动选择工件?

In your project home directory, there exists an .iml file add this under <library> : <jarDirectory url="url to the folder containing jars" recursive = "true">在您的项目主目录中,存在一个 .iml 文件,将其添加到<library> : <jarDirectory url="url to the folder containing jars" recursive = "true">

Worked for me.为我工作。

Based on this SO post from 2 years ago, adding JARs recursively from a directory is not currently supported in IntelliJ, although there is request for this feature to be added in a future release.基于 2 年前的这篇 SO 帖子,IntelliJ 目前不支持从目录递归添加 JAR,尽管有人要求在未来版本中添加此功能。

Your question is not a duplicate because the post cited above is IntelliJ version 12 and you are using version 14. If anyone has evidence that this feature has made it into version 14 please add a comment to this answer.您的问题不是重复的,因为上面引用的帖子是 IntelliJ 版本 12,而您使用的是版本 14。如果有人有证据表明此功能已进入版本 14,请在此答案中添加评论。

On IntelliJ 2019.2在 IntelliJ 2019.2 上

  1. Open the "Project Structure" (Command-;)打开“项目结构”(Command-;)
  2. Select "Libraries" from the left list从左侧列表中选择“库”
  3. Push the + button to add a library, navigate to directory or your choice and click "Open".按 + 按钮添加库,导航到目录或您的选择,然后单击“打开”。 When IntelliJ asks to identify the category of files of the directory, pick "Jar Directory".当 IntelliJ 要求识别目录的文件类别时,选择“Jar Directory”。
  4. Click "OK" and close this window.单击“确定”并关闭此窗口。
  5. Locate the .idea/libraries/system.xml file in your project and open it.在您的项目中找到 .idea/libraries/system.xml 文件并打开它。
  6. Locate the entry for the folder you just added as a library and change the 'recursive' argumument from false to true.找到您刚刚添加为库的文件夹的条目,并将“递归”参数从 false 更改为 true。
  7. Save the file保存文件

As soon as you save IntelliJ will recurse through the directories and add all the jars it can find to the entry of your library in the project navigator.保存后,IntelliJ 将递归遍历目录并将它可以找到的所有 jar 添加到项目导航器中库的条目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM