How do I import jars into my java program?

前端 未结 13 1556
自闭症患者
自闭症患者 2021-01-04 12:52

I\'ve downloaded two jars. I want to import some of their contained classes. How do I do this?

It\'s for my algorithms class. I\'ve tried following the instructions

13条回答
  •  旧巷少年郎
    2021-01-04 13:33

    If you are getting the "cannot be resolved to a type" error, and have tried adding the stdlib.jar or algs4.jar files, here is the solution:

    The libraries in stdlib.jar and algs4.jar are in the "default" package. In Java, you can't access classes in the default package from a named package. If you need to use the libraries with a named package, you can use these package versions:

    stdlib-package.jar and algs4-package.jar.

    You can download these files here: http://algs4.cs.princeton.edu/code/

    Then you can automatically add the import: import edu.princeton.cs.algs4.ClassName

提交回复
热议问题