In the
URLTester.java skeleton, create an array holding the URL of the file (directory name) specified from the
command line, as args[0]
.
Create an instance of URLClassLoader
, using this array in its constructor.
Next, have the test program load a class whose name will be provided from the command line, also, as args[1]
.
After loading the class, create an instance of it. You can use reflection and the Constructor
object, or just the
newInstance
method if the class has a no argument constructor.
The
Tester.java file contains a test class to use for the class loader. The only thing it does is print messages
when the class file is loaded and instances are created. Save and compile the file.
If you have a ".
" in your CLASSPATH
, move the Tester.class
file to another directory.
Run the URLTester
program. The first argument to the program is the directory you just moved the Tester.class
file to.
The second argument is the class you wish to load, Tester
.
To demonstrate the flexibility of the URLClassLoader
, place the Tester.class
file in a JAR file. Then, tell the
URLTester
program to load the file from the JAR file, instead of a directory.