Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a .class file in IntelliJ Java Project

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.

like image 538
DeveloperInToronto Avatar asked Aug 26 '12 20:08

DeveloperInToronto


People also ask

How do I view .class files in IntelliJ?

Open the necessary . class file in the editor in IntelliJ IDEA and then select View | Show Bytecode from the main menu. If you're not seeing this option, make sure that the bundled Bytecode Viewer plugin is enabled.

How do I add a class to a project in IntelliJ?

In the Project tool window ( Alt+1 ), right-click the node in which you want to create a new class and select New | Java Class. Alternatively, select the node, press Alt+Insert , and select Java Class.

How do I decompile a class file in IntelliJ?

Java bytecode decompiler The decompiler is enabled by default. Open a compiled . class file in the editor. If it's the first time that you're opening a compiled file, the IDE prompts you to agree to the specified terms and conditions in the JetBrains Decompiler dialog.


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

like image 117
Ingo Kegel Avatar answered Sep 20 '22 03:09

Ingo Kegel


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

like image 23
Sal Avatar answered Sep 19 '22 03:09

Sal