正确的方法将外部罐子(lib/*。jar)添加到Intellij Idea Project

发布于 2025-01-30 06:34:33 字数 217 浏览 3 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

泪意 2025-02-06 06:34:33

Intellij Idea 中添加外部罐子的步骤:

  1. 单击文件从工具栏
  2. 选择项目结构选项() ctrl + shift + alt + s s 在Windows/linux上, + ; 在Mac OS X上)
  3. 选择模块在左图下
  4. 选择依赖项 TAB
  5. 选择+ ICON
  6. 选择 1 Jars或Directories 选项

dialogue in Intellij 20.3

Steps for adding external jars in IntelliJ IDEA:

  1. Click File from the toolbar
  2. Select Project Structure option (CTRL + SHIFT + ALT + S on Windows/Linux, + ; on Mac OS X)
  3. Select Modules at the left panel
  4. Select Dependencies tab
  5. Select + icon
  6. Select 1 JARs or directories option
眼眸里的那抹悲凉 2025-02-06 06:34:33

Intellij Idea 15& 2016

  1. 文件> 项目结构...

    “文件项目结构”>

    或按 ctrl + alt + shift + s

  2. 项目设置> 模块> 依赖项> “ +”标志> 罐子或目录...

    “模块依赖项> jar or directories> jar或directories”>

  3. 选择罐子文件并单击确定,然后单击另一个确定按钮以确认

    “在此处输入图像说明”

    “在此处输入图像说明”

  4. 您可以在“外部库”中查看jar文件

    “在此处输入映像”

IntelliJ IDEA 15 & 2016

  1. File > Project Structure...

    File > Project Structure

    or press Ctrl + Alt + Shift + S

  2. Project Settings > Modules > Dependencies > "+" sign > JARs or directories...

    Modules > Dependencies > JAR or directories

  3. Select the jar file and click on OK, then click on another OK button to confirm

    enter image description here

    enter image description here

  4. You can view the jar file in the "External Libraries" folder

    enter image description here

飘落散花 2025-02-06 06:34:33

只需复制“ 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...

enter image description here

半窗疏影 2025-02-06 06:34:33

如果您正在使用Gradle构建项目,则只需要在build.gradle中的依赖项中添加一行:

buildscript {
    ...
}
...

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

然后将文件夹添加到您的root项目或模块中:

“在此处输入图像描述”

然后您将罐子放入在那里,你很高兴:-)

If you are building your project with gradle, you just need to add one line to the dependencies in the build.gradle:

buildscript {
    ...
}
...

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

and then add the folder to your root project or module:

enter image description here

Then you drop your jars in there and you are good to go :-)

记忆で 2025-02-06 06:34:33

您将它们添加到模块中。

我通常在源中有一个/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.

冰葑 2025-02-06 06:34:33

我使用此方法,它运行良好:

1-在libs文件夹下复制并粘贴.jar文件。

2-添加编译Filetree(dir:'libs',包括:'*.jar') to 依赖项 in build> build> build.gradle然后libs文件夹中的罐子将包括在内。3-

右键单击libs文件夹,然后从列表中选择“添加AS Library”选项。

I use this method and it works well:

1- Copy And paste the .jar files under the libs folder.

2- Add compile fileTree(dir: 'libs', include: '*.jar') to dependencies in build.gradle then all the jars in the libs folder will be included..

3- Right click on libs folder and select 'Add as library' option from the list.

几味少女 2025-02-06 06:34:33

您可以将罐子放入LIBS文件夹中,然后从那里添加。 以两种不同的方式完成

  1. 可以在Intellij:右键单击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:

  1. Right-click on the libs folder and add from there:

enter image description here

  1. Add the JAR from the project structure:

enter image description here

濫情▎り 2025-02-06 06:34:33

如果未正确添加到项目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

忆悲凉 2025-02-06 06:34:33
  1. 文件>项目结构
  2. 项目设置>模块>依赖项(选择一个)
    • 1罐或目录...
    • 2库...
    • 3个模块依赖关系...
  3. apply + ok

”在此处输入图像描述

  1. 导入到Java类中
  1. File > Project Structure
  2. Project Settings > Modules > Dependencies (Select one of)
    • 1 JARs or Directories...
    • 2 Library...
    • 3 Module Dependency...
      enter image description here
  3. Apply + Ok

enter image description here

  1. Import into java class
缱绻入梦 2025-02-06 06:34:33

这里找到了一些很大的帮助。但是,尽管正确加载了罐子,但我仍然无法正常工作。稍后,我发现我在文件结构而不是常规文件夹中意外创建了模块,并且该模块是在项目设置中预先选择的。

这是足迹:

文件 - >项目结构 - >模块 - > (如果有更多的话,请选择适当的模块) - >依赖项 - > + - >罐子或库

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:

File -> Project Structure -> Modules -> (select proper module if you have more) -> Dependencies -> + -> JAR or Libraries

穿透光 2025-02-06 06:34:33

尽管我同意以前的答案,但必须注意如何访问这些外部库的代码。

例如,要在外部库中访问类,您将需要使用 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.

enter image description here

你的心境我的脸 2025-02-06 06:34:33

我正在与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 ;)

最单纯的乌龟 2025-02-06 06:34:33

如果您在Intellij项目中使用Gradle Build System,请使用以下内容添加本地JAR库文件。

build.gradle.kts:

dependencies {
    implementation(
        files(
            "$rootDir/myLibs/my-library.jar",
            "another/path/to/library-2.aar",
            // etc.
        )
    )
    // Other dependencies...
}

If you are using Gradle build system for your IntelliJ project, use the following to add local JAR library files.

build.gradle.kts:

dependencies {
    implementation(
        files(
            "$rootDir/myLibs/my-library.jar",
            "another/path/to/library-2.aar",
            // etc.
        )
    )
    // Other dependencies...
}
橙味迷妹 2025-02-06 06:34:33

如果您使用Maven构建项目,则只需要在pom.xml中的依赖项中添加一行:

<dependency>
     <groupId>com.xxx</groupId>
     <artifactId>xxxx-server</artifactId>
     <version>1.0.0</version>
     <scope>system</scope>
     <systemPath>${pom.basedir}/src/libs/xxx-server-1.0.0.jar</systemPath>
</dependency>

然后将文件夹添加到root项目或模块中:

这是我的个人经历。我希望他们能帮助你

If you are building your project with maven, you just need to add one line to the dependencies in the pom.xml:

<dependency>
     <groupId>com.xxx</groupId>
     <artifactId>xxxx-server</artifactId>
     <version>1.0.0</version>
     <scope>system</scope>
     <systemPath>${pom.basedir}/src/libs/xxx-server-1.0.0.jar</systemPath>
</dependency>

and then add the folder to your root project or module:

enter image description here

this is my personal experiences. I wish they would help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文