How to use libraries for Algorithms part I Coursera course in Eclipse

前端 未结 10 901
挽巷
挽巷 2020-12-23 12:44

I\'ve started Coursera Algorythms course. Practice assignments must be done on Java and they suggest using DrJava as IDE, but it\'s really unconvenient. So I\'d like to use

相关标签:
10条回答
  • 2020-12-23 13:07

    It is probably because there is no package structure in the libraries, so you can't import classes from it. This might help you, How to use classes in Referenced Libraries in Eclipse.

    0 讨论(0)
  • 2020-12-23 13:08

    Incase of Gradle, add the maven repository entry in repositories section of build.gradle as follows:

    repositories {
        mavenCentral()
        maven {
            url 'https://dl.bintray.com/algs4/maven/'
        }
    }
    

    Add the dependency as follows:

    compile group: 'edu.princeton.cs', name: 'algs4', version: '1.0.4'
    

    In case of Maven, add the entry in repositories tag in build.xml, as follows:

    <repositories>
      <repository>
        <id>org.coursera.algs4</id>
        <name>Algs4 lib</name>
        <url>https://dl.bintray.com/algs4/maven/</url>
      </repository>
    </repositories>
    

    Add the dependency as follows:

    <dependencies>
      <dependency>
        <groupId>edu.princeton.cs</groupId>
        <artifactId>algs4</artifactId>
        <version>1.0.4</version>
      </dependency>
    </dependencies>
    
    0 讨论(0)
  • 2020-12-23 13:14

    One option is that there is a maven repo on github provided by slok. The bad part of this is the jars added were those using the default package, so you can't use a package structure.

    UPDATE: I have added the package versions of the jar to the repo and created a pull request it has now been accepted.

    Note that I have changed the identifiers to match the original package structure from Princeton.

    <dependencies>
      <dependency>
        <groupId>edu.princeton.cs.introcs</groupId>
        <artifactId>algs4-package</artifactId>
        <version>1.0</version>
      </dependency>
    
      <dependency>
        <groupId>edu.princeton.cs.introcs</groupId>
        <artifactId>stdlib-package</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>
    
    <repositories>
      <repository>
        <id>org.coursera.algs4</id>
        <name>Algs4 coursera course custom repository</name>
        <url>https://raw.github.com/slok/algs4-mvn-repo/master</url>
      </repository>
    </repositories>
    
    0 讨论(0)
  • 2020-12-23 13:15

    Follow the below steps

    Right click on your project > Properties. It will open the following window

    enter image description here

    Select "Java Build Path" from the left side. Now select "Libraries" tab from the right side

    enter image description here

    Click on "Add External Jars"

    enter image description here

    Add the Jar files.

    Now you are done

    0 讨论(0)
提交回复
热议问题