在 IntelliJ Java 项目中引用 .class 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12133823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:43:32  来源:igfitidea点击:

Referencing a .class file in IntelliJ Java Project

javaintellij-idea.class-file

提问by DeveloperInToronto

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.

我刚开始玩 IntelliJ。我需要从我下载的类文件中调用一个函数,所以我需要在我的项目中引用一个 .class 文件。不知道如何将它添加到我的项目中。如果有人可以指导我,我将不胜感激。

回答by Ingo Kegel

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.

用“File->Project Structure”打开项目结构对话框,选择左侧的“Project Settings->Modules”,然后选择要修改classpath的模块。在对话框右侧的“依赖项”选项卡上,您可以添加类文件的类路径根目录。

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.

当然class文件必须在class所在的包对应的正确目录结构中,否则是不行的。

回答by Sal

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

选择项目的根目录并按 F4。然后你会看到项目结构。选择左侧的“库”部分,然后单击加号以创建“新项目库”。选择“Java”并选择 .class 文件所在的目录。单击“确定”继续其余步骤。

回答by Kaden Bevan

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.

要进入依赖项选项卡,双击“src”文件夹,然后单击右上角的绿色加号按钮。单击“JAR 或目录”,然后添加 .class 文件的父文件夹。

回答by Farzad Vertigo

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.

对于较新版本的 Intellij,按 Ctrl + Alt + Shift + s 打开项目设置,然后选择 Modules,在 Dependencies 选项卡下选择绿色 + 并添加 .class 文件所在的文件夹。在范围下,选择编译。