正确的方法将外部罐子(lib/*。jar)添加到Intellij Idea Project
在Intellij Idea中创建新的Java项目时,会创建以下目录和文件:
./projectname.iml
./projectname.ipr
./projectname.iws
./src/
我想配置Intellij Idea以在./ lib/*。 > 在Intellij Idea中实现这一目标的正确方法是什么?
When creating a new Java project in IntelliJ IDEA, the following directories and files are created:
./projectname.iml
./projectname.ipr
./projectname.iws
./src/
I want to configure IntelliJ IDEA to include my dependency JARs in ./lib/*.jar
to the project.
What is the correct way to achieve this in IntelliJ IDEA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
在 Intellij Idea 中添加外部罐子的步骤:
Steps for adding external jars in IntelliJ IDEA:
Intellij Idea 15& 2016
文件> 项目结构...
或按 ctrl + alt + shift + s
项目设置> 模块> 依赖项> “ +”标志> 罐子或目录...
选择罐子文件并单击确定,然后单击另一个确定按钮以确认
您可以在“外部库”中查看jar文件
IntelliJ IDEA 15 & 2016
File > Project Structure...
or press Ctrl + Alt + Shift + S
Project Settings > Modules > Dependencies > "+" sign > JARs or directories...
Select the jar file and click on OK, then click on another OK button to confirm
You can view the jar file in the "External Libraries" folder
只需复制“ libs”文件夹(或整个“ libs”文件夹)下的.jar,右键单击它,然后从列表中选择'添加为库'选项。它将完成其余的...
Just copy-paste the .jar under the "libs" folder (or whole "libs" folder), right click on it and select 'Add as library' option from the list. It will do the rest...
如果您正在使用Gradle构建项目,则只需要在build.gradle中的依赖项中添加一行:
然后将文件夹添加到您的root项目或模块中:
然后您将罐子放入在那里,你很高兴:-)
If you are building your project with gradle, you just need to add one line to the dependencies in the build.gradle:
and then add the folder to your root project or module:
Then you drop your jars in there and you are good to go :-)
您将它们添加到模块中。
我通常在源中有一个
/lib
目录。我将所有需要的罐子放在那里,添加 /lib作为库,并将其作为我的模块依赖性的一部分。2018更新:我现在正在使用Intellij 2017/2018。
我完全致力于Maven和Nexus进行依赖管理。
这就是世界走的方式。我知道的每个开源Java项目都使用Maven或Gradle。你也应该。
You add them as libraries to your module.
I usually have a
/lib
directory in my source. I put all the JARs I need there, add /lib as a library, and make it part of my module dependencies.2018 update: I'm using IntelliJ 2017/2018 now.
I'm fully committed to Maven and Nexus for dependency management.
This is the way the world has gone. Every open source Java project that I know of uses Maven or Gradle. You should, too.
我使用此方法,它运行良好:
1-在
libs
文件夹下复制并粘贴.jar
文件。2-添加
编译Filetree(dir:'libs',包括:'*.jar')
to依赖项
inbuild> build> build.gradle
然后libs
文件夹中的罐子将包括在内。3-右键单击
libs
文件夹,然后从列表中选择“添加AS Library”选项。I use this method and it works well:
1- Copy And paste the
.jar
files under thelibs
folder.2- Add
compile fileTree(dir: 'libs', include: '*.jar')
todependencies
inbuild.gradle
then all the jars in thelibs
folder will be included..3- Right click on
libs
folder and select 'Add as library' option from the list.您可以将罐子放入LIBS文件夹中,然后从那里添加。 以两种不同的方式完成
:
You can put the JAR in the libs folder and add it from there. This can be done in 2 different ways in IntelliJ:
如果未正确添加到项目gradle文件中,则库不能直接在任何程序中使用。
智能IDS来完成此操作
可以在Inteli J. 1)首先作为judent of Project src文件下添加文件夹名称“ libs'的 。 (可以使用IDE本身可以轻松完成)
2)然后将您的库文件(例如:JAR文件)复制到名为“ Libs”的文件夹
3)现在您可以在Libs文件夹中看到库文件。现在右键单击文件,然后选择“添加为库”。这将修复您程序中的所有相关文件,并且库将直接用于您的使用。
请注意:
每当您将库添加到项目中时,请确保项目支持库
Libraries cannot be directly used in any program if not properly added to the project gradle files.
This can easily be done in smart IDEs like inteli J.
1) First as a convention add a folder names 'libs' under your project src file. (this can easily be done using the IDE itself)
2) then copy or add your library file (eg: .jar file) to the folder named 'libs'
3) now you can see the library file inside the libs folder. Now right click on the file and select 'add as library'. And this will fix all the relevant files in your program and library will be directly available for your use.
Please note:
Whenever you are adding libraries to a project, make sure that the project supports the library
这里找到了一些很大的帮助。但是,尽管正确加载了罐子,但我仍然无法正常工作。稍后,我发现我在文件结构而不是常规文件夹中意外创建了模块,并且该模块是在项目设置中预先选择的。
这是足迹:
Some great help found here. However, I still could not make it to work despite loading JAR properly. I found out later that I accidentally created module in the file structure instead of regular folder and this very module was pre-selected in the project setting.
Here is the footprint:
尽管我同意以前的答案,但必须注意如何访问这些外部库的代码。
例如,要在外部库中访问类,您将需要使用 import 关键字,然后使用外部库的名称,持续使用点表示法,直到达到所需的类。
查看下图,以查看我如何从QuickFixJ库中导入 codeGenerationException 类。
While I agree with the previous answers, it's important to note how to access the code of those external libraries.
For example to access a class in the external library, you will want to use the import keyword followed by the external library's name, continued with dot notation until the desired class is reached.
Look at the image below to see how I import CodeGenerationException class from the quickfixj library.
我正在与Kotlin一起使用Intellij Idea 2022。
在项目的根部以及build.gradle.kts文件中创建libs文件夹{} {}:
sumpareation(filetree(mapof(“ dir” to'libs'to'libs''),include“ to listof(“*。jar”)) ))
希望这可以帮助来到这个帖子的人,他们像我一样努力实施外部依赖关系;)
I'm using Intellij IDEA 2022, with Kotlin.
Created libs folder in the root of the project, and in build.gradle.kts file within dependencies {}:
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
Hope this helps someone who came to this post struggling to implement external dependencies, like me ;)
如果您在Intellij项目中使用Gradle Build System,请使用以下内容添加本地JAR库文件。
build.gradle.kts:
If you are using Gradle build system for your IntelliJ project, use the following to add local JAR library files.
build.gradle.kts:
如果您使用Maven构建项目,则只需要在pom.xml中的依赖项中添加一行:
然后将文件夹添加到root项目或模块中:
这是我的个人经历。我希望他们能帮助你
If you are building your project with maven, you just need to add one line to the dependencies in the pom.xml:
and then add the folder to your root project or module:
this is my personal experiences. I wish they would help you