Question

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.

Était-ce utile?

La solution

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.

Autres conseils

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'.

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top