|
Help | Solution | API Docs | Expected Output
Help is available for each task, or you can go straight to the solution source code.
In the
URLTester.java skeleton, create an array holding the URL of the file (directory name) specified from the
command line, as
URL urlList[] = {new File(args[0]).toURL()};
Create an instance of ClassLoader loader = new URLClassLoader(urlList);
Next, have the test program load a class whose name will be provided from the command line, also, as Class c = loader.loadClass (args[1]);
After loading the class, create an instance of it. You can use reflection and the Object tester = c.newInstance(); 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. Shift-click on the Tester.java link to save. Then compile with the following command: javac Tester.java
If you have a " Something like the following will do. Depending upon your platform, the specific command may vary. mkdir test move Tester.class test
Run the java URLTester test Tester
To demonstrate the flexibility of the jar cf test.jar -C test Tester.class java URLTester test.jar Tester Copyright © 1998 MageLang Institute. All Rights Reserved. | ||||||||||||
|
| ||||||||||||