There is a folder and in it are already compiled classes. How to call methods from them? Threw in the project directory, and wrote

import javax.help; 

As a result, Error: (15, 18) java: package javax.help does not exist.

  • those. did you just add the .class files to the project? - Kirill Stoianov
  • one
    Ideally, you need to pack all these .class files into the .jar archive, and then connect the .jar library to your project, take a look here.stackoverflow.com/q/3754/191718 - Kirill Stoianov

1 answer 1

Console example

Directory structure:

 C:\dev\ TestImp.class c:\dev\mypack\ Test.class 

Test class code:

 package mypack; public class Test { public Test() { System.out.println("I live!"); } } 

TestImp class code:

 import mypack.Test; public class TestImp { public static void main(String[] args) { Test t = new Test(); } } 

In the console, go to the c: \ dev \ directory and execute:

 java TestImp 

The console displays:

 I live! 

UPD:

As for Intellj Idea - you need to pack your class files in the jar command

 jar cf test.jar Test1.class 

After that, import the jar into the project as follows:

 Структура проекта (CTRL + SHIFT + ALT + S on Windows/Linux, ⌘ + ; on Mac OS X) Modules на левой панели. Вкладка Dependencies '+' → JARs or directories 

UPD2:

Intellij IDEA allows you to add not only JARs, but also directories with classes. It is done completely the same as written above, only the directory with classes is selected. After selecting, a dialog opens in which you can exclude any subdirectories of the selected directory.

  • It is not necessary to pack in jar, you can connect the folder with class files to the project. - Roman
  • @Roman I will try in the evening and if it is confirmed, I will edit the answer. - GreyGoblin 1:49 pm
  • @Roman works with folders too. Completed the answer. - GreyGoblin