aspose file tools*
The moose likes Java in General and the fly likes Loading and instantiating a remote class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Loading and instantiating a remote class?" Watch "Loading and instantiating a remote class?" New topic
Author

Loading and instantiating a remote class?

Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Hi all,

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)


Thanks & Regards


Naseem


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can't call a method on a class that isn't in the same JVM.

Have you tried RMI?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Naseem --

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.


[Jess in Action][AskingGoodQuestions]
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Thanks Friedman. Thanks Aviroop.

Yeah it worked as said when I accessed it from tomcat servlet container.



Here is my Hello Bean class




Thanks & Regards


Naseem
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
Thanks for posting the code Naseem.

Thanks Friedman. Thanks Aviroop.

By the way, who is Aviroop?


SCJP 1.4 85%
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading and instantiating a remote class?