saul.shanabrook
saul.shanabrook

Reputation: 3168

Use Java class file in IDEA

Is it possible to use a class from a .class file in IDEA? For example, if I have a directory with two files Ball.java and DemoBall.class, how would I use DemoBall in Ball? It says it cannot find symbol when compiling. I just want to tell IDEA that there is a compiled Java class in the directory and to recognize that, I don't want to decompile it.

Upvotes: 1

Views: 133

Answers (1)

nIcE cOw
nIcE cOw

Reputation: 24616

EDIT:

  1. Open IntelliJIDEA. Now Press CTL + Shift + ALT + S. This will open Project Structure.
  2. Now Select Module from Project Settings (left hand side). And Dependencies tab from the right hand side.
  3. Now Click on the + on the extreme right hand side toolbar. Select Jars or Directories. A new Window, Attack File or Directories will pop up.
  4. Now browse to the location, where DemoBall.class is located. Click OK.
  5. Select the CheckBox under Export against the location just selected. Click OK on the main Project Structure window. You are done.

Original(This one it seems is not the right way):

  1. Open IntelliJDEA. Create a Project, with simple Java Class named Ball.java inside it, having one main method(empty body).
  2. Run this class, so as to create one out folder.
  3. Copy DemoBall.class. Now through Windows Explorer/File System, go to out folder and paste DemoBall.class inside out\production\ProjectName folder.
  4. Now simply write the code that uses this DemoBall class, inside the main method of Ball.java class.

Previously, I was wondering, as to why the red lines are coming still, even though, the program is running fine. But once, I restart, IntelliJIDEA, everythingy works fine, without showing any errors.

Upvotes: 1

Related Questions