| Author |
loading classes
|
peter cooke
Ranch Hand
Joined: Mar 16, 2004
Posts: 310
|
|
I am in a situation I do not understand and will attempt to explain it as best as i can. I have created a simple rmi "echo" client/server application straight from one of the sun courses. it has a class echo.server that only rebinds echo objects to the rmi registry. I can compile and properly the client server rmi process when the interface, impl class, stubs/skeletons are all in the same application.jar. my java command line looks like java -cp application.jar echo.server If I move these the remote interface, impl, stub/skeleton to a library.jar. all compiles properly. However, I recieve unmarshing error Echo ClassNotFoundException when I attempt to run it. java -cp library.jar;application.jar echo.server Why would simply moving the remote things to a package that I can share amongst many applictions be disallowed? I
|
CIAO Peter M. Cooke
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
|
Can you provide a short list of what is in each of the JARs? Also, what class is not found that throws the ClassNotFoundException?
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
peter cooke
Ranch Hand
Joined: Mar 16, 2004
Posts: 310
|
|
If everhting is in one jar all works fine. In non-working scenario. All classes are packaged in appropriate directory structure. the applciation jar contains EchoServer.java at it's top. libary jar has a EchoApp Directory that contains the remote interface, implementation, stub/skeleton classes. rmic -v1.1 remote interface Impl class [ February 02, 2005: Message edited by: peter cooke ] [ February 02, 2005: Message edited by: peter cooke ]
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
OK, I was able to run your example - what you need to do is set the codebase property for your server. The ClassNotFoundException is thrown because the RmiRegistry can't find your stub to save in the registry. All you have to do is change your command line to look something like - (NEP - edited to break up really long command prompt line.) [ February 03, 2005: Message edited by: Nathan Pruett ]
|
 |
peter cooke
Ranch Hand
Joined: Mar 16, 2004
Posts: 310
|
|
Nathan thanks so much. Have one last question. Ok I found the documentation on sun about codebase. Would you happen to know the reason why I must specify the codebase? [ February 03, 2005: Message edited by: peter cooke ]
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
Section 3.2 in this RMI documentation gives a pretty good description. Basically, codebase is kind of like a classpath for the remote code. If a client can't load a class in it's local classpath, it will look in the server's codebase for it.
|
 |
Shawn Kuenzler
Ranch Hand
Joined: Apr 16, 2006
Posts: 73
|
|
Nearly three years later but just wanted to say thanks to Nate for answering this... I had the exact same problem (worked unjar'd, threw the classNotFound when the application was jar'd). Interesting though, Sun says you don't need a codebase if you're using 1.5 (which I am). How come I needed the codebase afterall? Sun's example and explanation Note: If the server needs to support clients running on pre-5.0 VMs, then a stub class for the remote object implementation class needs to be pregenerated using the rmic compiler, and that stub class needs to be made available for clients to download. See the codebase tutorial for more details.
|
SCJP 1.5
|
 |
 |
|
|
subject: loading classes
|
|
|