1

I have a folder of .jar files on my desktop. I want my program to be able to access the class files in the jars and create instances of them. How do I do this?

Edit: The jars are added by the user of my program. I know what folder they are in, and can figure out their names.

trimill
  • 13
  • 1
  • 6

2 Answers2

0

Include the JAR in the classpath.

Lew Bloch
  • 3,364
  • 1
  • 16
  • 10
0

Include the jar on the classpath:

java -classpath [PATH_TO_JAR] YOUR_CLASS

And on your classes import the classes you wish to use:

import package.CLASS_2_USE_1 Import package.CLASS_2_USE_2

This assuming the classes are public.

Edit: If you want to load classes form jars supplied at runtime it's probably a good idea to agree on a fixed set of methods and class names. You can see how to do it on this thread:

How should I load Jars dynamically at runtime?

Joao
  • 86
  • 5