Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install apache commons library for 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?

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

Solved this way:

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

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

Not solved with Maven: enter image description here

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

1

enter image description here

2

enter image description here

How to fix it?

enter image description here

like image 218
J.Olufsen Avatar asked Oct 16 '13 21:10

J.Olufsen


1 Answers

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 automatically adds the dependencies to the classpath.

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

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.

like image 141
axiopisty Avatar answered Nov 15 '22 21:11

axiopisty