Java 如何为 IntelliJ IDEA 安装 apache 公共库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19413957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:57:07  来源:igfitidea点击:

How to install apache commons library for IntelliJ IDEA?

javaintellij-idea

提问by J.Olufsen

commons-lang3-3.1-bin.zipwas downloaded from commons.apache.organd extracted to folder with java jdk/lib. I need to import Stopwatch from this library. How to do it for IntelliJ IDEA?

commons-lang3-3.1-bin.zipcommons.apache.org下载并解压到带有 java 的文件夹jdk/lib。我需要从这个库中导入秒表。如何为 IntelliJ IDEA 做到这一点?

Update: Why can't intelliJ just add pom.xml to existing project without trying to delete it? enter image description here

更新:为什么 intelliJ 不能将 pom.xml 添加到现有项目而不尝试删除它? 在此处输入图片说明

Solved this way:

解决了这个方法:

Downloaded a lib from http://commons.apache.org/intelliJ > Project Structure > Dependencies> + > Library > path to lib from commons.apache.org

http://commons.apache.org/intelliJ> 项目结构 > 依赖 > + > 库 > 从 commons.apache.org 到 lib 的路径下载了一个库

PS. Still looking for a way to solve this using Maven...

附注。仍在寻找使用 Maven 解决此问题的方法...

Not solved with Maven:enter image description here

没有用 Maven 解决:在此处输入图片说明

Cannot Run project. Have to probably I have to configure it somehow...

无法运行项目。不得不可能我必须以某种方式配置它......

1

1

enter image description here

在此处输入图片说明

2

2

enter image description here

在此处输入图片说明

How to fix it?

如何解决?

enter image description here

在此处输入图片说明

采纳答案by axiopisty

If you can use Mavenor Gradle, then you can include the library as a dependency:

如果您可以使用Maven或 Gradle,那么您可以将库作为依赖项包含在内:

$ tree
.
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- test
    |           `-- App.java
    `-- test
        `-- java
            `-- test
                `-- AppTest.java

7 directories, 3 files

pom.xml

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>myGroup</groupId>
  <artifactId>myArtifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>deleteme</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.1</version>
    </dependency>
  </dependencies>
</project>

IntelliJ automatically adds the dependencies to the classpath.

IntelliJ 自动将依赖项添加到类路径。

If you open the pom.xml file as a new project in IntelliJ, the dependency will automatically be added to the classpath.

如果在 IntelliJ 中将 pom.xml 文件作为新项目打开,则依赖项将自动添加到类路径中。

Edit

编辑

Otherwise, if you edit your project settings in IntelliJ, go to the modules section, and then the dependencies tab. You can add your dependencies there. See here.

否则,如果您在 IntelliJ 中编辑项目设置,请转到模块部分,然后转到依赖项选项卡。您可以在那里添加您的依赖项。见这里