How to use stdlib.jar in Intellij Idea?
Answered
Hi i'm learning the Sedgewick's book for Java and i want to use "stdlib.jar" in "Intelij Idea".
I simply go to Project Structure>Modules>Dependencies and add it to the list but when i want to write some code in "Intellij Idea", it seems that it doesn't work and i can't use the codes i want.
I've searched the internet and didn't find anything useful.
Here's a pic:
http://i.stack.imgur.com/FjORt.jpg
Help me if you can.
Please sign in to leave a comment.
Make sure the jar contains the class you are using and the jar is added to the dependencies of the module: http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html.
thanks for you fast response. i'm sure that it contains the class and i'm sure the jar is added, that is why i'm so confused about it.
Please share a sample project to reproduce the problem (including all the files and the jars).
ok.wait a moment
thank you for helping:)
here's the jar file : http://introcs.cs.princeton.edu/java/stdlib/stdlib.jar
here's some sample project
is anything else needed?
Your jar has all the classes in the default package (root of the jar). Java doesn't support importing classes from the default package, see http://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package for more details.
thank you so much:))))
i still can't solve my problem.i know that i look dumb because i'm new to java programming .would you please help me more?
if we can't use classes in the default package, what are they used for?
isn't there an easy way to use them?
is there an easy way to use the classes i need?
Here is one of the ways to fix it: ftp://ftp.intellij.net/pub/.idea/StdLibSample.zip.
I've unpacked the sources from the jar and Refactor | Moved them into stdlib package so that they can be imported.
You can then package them back into the jar inside stdlib package folder and use the jar library instead of having the sources for the library as in the sample project above.
i ca't run your sample code in intellij idea. the run button is off.sorry for being dumb :(
Right click on Main and run it from the context menu:
Make sure correct JDK is selected for the project:
See https://www.jetbrains.com/help/idea/2016.1/creating-and-editing-run-debug-configurations.html.
The website also have a package version of the library. Use this instead.
http://introcs.cs.princeton.edu/java/stdlib/stdlib-package.jar
Then you can use import statement:
Thank you @.... This solves my issues.
I have the same issue. Could you please help out? How to configure this stdlib package?
Thanks!
@... Please see: https://www.jetbrains.com/help/idea/working-with-module-dependencies.html#add-a-new-dependency
1. File > Project Structure... or press Ctrl + Alt + Shift + S.
2. Project Settings > Modules > Dependencies > "+" sign > JARs or directories...
3. Select the jar file and click on OK, then click on another OK button to confirm.
4. You can view the jar file in the "External Libraries" folder.