I just started playing around with IntelliJ. I need to call a function from a class file I downloaded, so I need to reference a .class file in my project. Can't figure out how to add it to my project. Would appreciate it if someone could guide me.
-
2Are you doing "Algorithms" course from corsea.org? I zipped class file to jar (zip) file and included it as dependency to the project – Eugen Martynov Aug 27 '12 at 20:17
-
Haha! yes actually. I'm more of a .Net developer so my question is pretty basic. The respond that I marked worked fine. The point was that (as opposed to .Net, in which you reference individual dlls in your project) you have to select a folder to identify your dependencies (not individual .class files) and everything within that folder would be accessible within the project. – DeveloperInToronto Aug 27 '12 at 20:24
4 Answers
Open the project structure dialog with "File->Project Structure", select "Project Settings->Modules" on the left, then select the module whose classpath you want to modify. On the "Dependencies" tab on the right side of the dialog you can add the classpath root directory of your class file.
Of course the class file has to be in the right directory structure corresponding to the package of the class, otherwise it will not work.

- 46,523
- 10
- 71
- 102
-
You're answer is not accurate in the new versions of IntelliJ, can you please update it? – Shimmy Weitzhandler Jan 17 '19 at 14:01
-
-
Couldn't find 'Dependencies'. Anyway, Sal's [answer](https://stackoverflow.com/a/12133959/75500) solved my issue. Thanks – Shimmy Weitzhandler Jan 18 '19 at 01:49
-
1@Shimmy "File->Project Structure", select "Project Settings->Modules", select a module, then there is a "Dependencies" tab on the right side. – Ingo Kegel Jan 18 '19 at 08:43
-
Would be nice if you include that in your answer, for people new to IntelliJ. – Shimmy Weitzhandler Jan 21 '19 at 02:41
Select the root of your project and press F4. Then you'll see the project structure. Select the 'Libraries' section on the left hand side and click the plus symbol to create a 'New Project Library'. Choose 'Java' and select the directory where the .class file(s) is located. Proceed the remaining steps by clicking 'OK'.

- 1,230
- 13
- 21
For the newer versions of Intellij, press Ctrl + Alt + Shift + s
to open project settings, then choose Modules, under Dependencies tab choose the green +
and add the folder in which your .class
file is located. Under scope, choose compile.

- 2,458
- 1
- 29
- 32
To get to the dependencies tab double click on the "src" folder, then click on the green plus button on the top right hand side. click "JARs or Directories", then add the parent folder of your .class file.

- 46
- 3