0

I've tried to link a jar-library to my project, but it doesn't seem to "completely" work..

I've used Project structure (shift+ctrl+alt+S) to add stdlib.jar, and the library seems to be linked to the program module on the Modules - Dependencies tab of the Project structure window (Sorry, I can't add images, need 10 rep)

When I create a class in the src folder of the project, I can use the classes/methods from stdlib.jar, but when I create a package inside src and then create new classes inside this package, I can't use the methods from stdlib.jar.

Intellij also gives no proposals to import anything, and I don't really know what import statement should I write (if this is what I need) since stdlib.jar is the name of the jar-file, but not the package/class name.

I'm also new to programming, but this question is about how to manage Intellij Idea IDE.

It was worth 4 hours of frustration, but I couldn't find a solution.

I've read Configuring Module Dependencies and Libraries, but couldn't find the exact answer for my problem. I've read many stackoverflow topics as well.

UPDATE: Here is the link to stdlib.jar. It is from the Sedgewick's booksite on algorithms.

UPDATE2: It really seems that stdlib.jar was designed for the default package and can't be used inside any other package (now the question is: why they do like this instead of making "universal" libraries?). But such infos are not in every book.

  • 1
    What is stdlib.jar and how was it created? It looks like all classes in stdlib.jar are in the default package. If a class is in the default package, it's not possible to import and use it from a different package. – yole Feb 02 '15 at 07:34
  • Btw, the question is new, this issue was never asked on stackoverflow (at least for IDEA IDE), so why -1 I don't understand – Omicron_Persei_11 Feb 02 '15 at 10:12

2 Answers2

3

All the classes in this .jar are in the default package. Those classes can't be imported by classes in any other package; that's why IntelliJ IDEA can't resolve references to those classes and doesn't provide any auto-import suggestions.

yole
  • 92,896
  • 20
  • 260
  • 197
1

I am learning this book, too.

You simply go to "Project Structure" and then select "Modules" on the left panel, and click on the "Dependencies" tab. Add stdlib.jar to it, and it just works.

hedgehog0
  • 64
  • 1
  • 10