Importing java files from outside normal jdk?
I know that if you want to import something, you say "import something.something.Something", like "import java.util.Set" or "import java.awt.event.*". But, is there a way to use the import statement to import files from other locations on your computer? Or, if not, is there any way to somehow incorporate them into your program without manually dragging them into whatever package you are using every time you want to use them?
- grezlbeLv 51 decade agoFavourite answer
If you have to import another program (say it is a class), you do not use the "import" reserved word. It is only for importing packages that contain the package code. For example, the package for BreezySwing is a .java program, however it cannot be executed. However, some IDEs require that you open both the BreezySwing package program, and the program you are working on in order for it to recognize the package. Otherwise it will give a "package does not exist error". In order to open seperate programs outside the program you are working on, you can click the open button in the top toolbar of your IDE.
- 1 decade ago
YOU CAN TRY THIS :
For example you have a java class file called MyTest.class. It is result after you compile MyTest.java. MyTest.class locate in a folder called C:\MyJavaProgram. You can try something like this if you want to use MyTest into your current java program.
1.Open Environment Variables.
2.Find a variable called classpath.
3.Click Edit and add C:\MyJavaProgram\MyTest.class into it
4.Now you can use MyTest in your current java program without you need to import it.
I have tried it. It success only if you compile and execute your current java program that use MyTest through command prompt. You can try using IDE.
I hope it help.Source(s): http://java2everyone.blogspot.com/