Referencing a .class file in IntelliJ Java Project

↘锁芯ラ 提交于 2019-12-01 13:57:51

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/12133823/referencing-a-class-file-in-intellij-java-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!