如何为IntelliJ IDEA安装apache commons库? [英] How to install apache commons library for IntelliJ IDEA?
问题描述
commons-lang3-3.1-bin.zip
是从 commons.apache.org 下载的,并且使用Java jdk/lib
提取到文件夹.我需要从该库中导入秒表.对于IntelliJ IDEA,该怎么做?
commons-lang3-3.1-bin.zip
was downloaded from commons.apache.org and extracted to folder with java jdk/lib
. I need to import Stopwatch from this library. How to do it for IntelliJ IDEA?
更新: 为什么intelliJ不能不尝试删除就将pom.xml添加到现有项目中?
Update: Why can't intelliJ just add pom.xml to existing project without trying to delete it?
已解决:
从 http://commons.apache.org/下载了一个库. intelliJ>项目结构>依赖关系> +>库>从commons.apache.org到lib的路径
Downloaded a lib from http://commons.apache.org/ intelliJ > Project Structure > Dependencies> + > Library > path to lib from commons.apache.org
PS.仍在寻找使用Maven解决此问题的方法...
PS. Still looking for a way to solve this using Maven...
无法通过Maven解决:
无法运行项目.可能我必须以某种方式进行配置...
Cannot Run project. Have to probably I have to configure it somehow...
1
2
如何解决?
推荐答案
If you can use Maven or Gradle, then you can include the library as a dependency:
$ tree
.
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- test
| `-- App.java
`-- test
`-- java
`-- test
`-- AppTest.java
7 directories, 3 files
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自动将依赖项添加到类路径.
IntelliJ automatically adds the dependencies to the classpath.
如果您在IntelliJ中将pom.xml文件作为新项目打开,则依赖项将自动添加到类路径中.
If you open the pom.xml file as a new project in IntelliJ, the dependency will automatically be added to the classpath.
修改
否则,如果您在IntelliJ中编辑项目设置,请转到模块"部分,然后转到依赖项"选项卡.您可以在此处添加依赖项.请参见此处.
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 IDEA安装apache commons库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!