Can any one please explain how to load and instantiate a class which is located on a different machine.
I tried this code but it throws ClassNotFoundException.
I have Test1 class at file://192.168.1.3/java/operators location. I am able to access it from windows explorer. 192.168.1.3 is the ip address of the m/c where Test1 class file is placed.
Can't I use file protocol here.
Here is the stack trace.
java.lang.ClassNotFoundException: Test1 at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at Test.main(Test.java:7)
You're actually on the right track, but I would guess that the problem is that that's not really a valid URL; it's a Windows fake file-sharing thingamabob. If the class file were served by an actual web server so that you could get it via an http:// URL, you should be able to get this to work.
I tried out the above program. However, I am getting the following runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: Test (wrong name: tes t) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
I placed the Hello.class file in the MyExamples folder which is inside the webapps folder. There is no problem with the installation of the Apache Tomcat webserver. What's amiss here?