running rmi server, classnotfound [duplicate]
Asked Answered
B

9

29

Hi I'm trying to run a java application that binds a class to the naming server, but i constantly get a ClassNotFoundException

First I start the registry:

rmiregistry

then from eclipse I try to execute the server but get this error

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at progInternet2008.Pozzobon.tesi.Slave.main(Slave.java:54) Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory 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:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592) at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628) at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294) at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238) at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1531) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1493) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) ... 12 more

I've read the RMI Java tutorial but still could not get it working...

As VM Arguments I've set this:

-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008

please help me

(I'm using Java 6)

Bayonne answered 21/1, 2009 at 10:12 Comment(2)
Did you end up fixing this problem?Valuator
A file: codebase URL is only going to work when client and server are on the same machine, in which case you don't need the codebase feature at all, or when it refers to a shared drive that looks the same from client and server, which implies a LAN, where again it is dubious whether you need the feature at all.Premiership
N
74

Run the rmiregisrty command from your /bin, /build, or /build/classes folder, whichever folder is the root of your built files.

I spent half a day trying to solve that same thing.

Numerable answered 9/11, 2015 at 2:3 Comment(6)
Thank you very much! It just worked for the easiest run (local only).Blade
You saved 25 people!Germinal
Thank you, this was the answer I needed! I took it a step further and just fired up the registry within my code using the command LocateRegistry.createRegistry(1099);Pawnshop
How did you find that out?Stakeout
@Pawnshop You deserve a medalCowles
For intellij guys, the folder is out/production/myrmi. The one that has .class filesCowles
T
27

The exception is occurring because the rmiregistry application doesn't know where to load classes from. When you attempt to bind an object in the RMI registry, the registry downloads the class definition for that object. Some of the other answers are telling you to get around this by setting the classpath for the rmiregistry app so that it has the class definitions when it is started and doesn't need to download anything, but Sun's Java RMI tutorial explicitly says not to do this. I suspect this has the potential to cause conflicts between the version of the class in the registry and the class on the server.

The correct way to handle the problem is to set the java.rmi.server.codebase property as you were trying to do. The property requires that a directory path be terminated with a forward slash, like so:

-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008/

You may also be having trouble if the ${workspace_loc} variable is a relative path and the rmiregistry application was not started in the same directory so the relative path is not correct for it. If you either make the path absolute, or start the rmiregistry in the appropriate directory, the ClassNotFoundException should go away. See the tutorial on the java.rmi.server.codebase property for a little more detailed information.

Tussis answered 22/4, 2009 at 22:55 Comment(1)
The tutorial is only saying that because it is using the codebase feature, and it breaks the codebase feature. It's not a issue otherwise.Premiership
V
7

Okay I just overcame this problem. Make sure when you run rmiregistry that your CLASSPATH environment variable is set.

For example, you might have a script:

set CLASSPATH=[path to jdbc driver].jar
rmiregistry.exe

This was all I needed to get my lost classpath working. I'm not sure how to send -cp commandline to rmiregistry.exe. Its documentation is quite lacking.

Valuator answered 16/2, 2009 at 21:18 Comment(3)
Sun's RMI tutorials explicitly tell you not to do this. It can cause problems.Tussis
@A.Levy Where exactly do they say that? The only way this can cause a problem is if the codebase feature is being used.Premiership
upvote. this is the only fix that works from the last 10 questions around. useCodeBaseOnly=false doesnt work as argument. -Djava.security.policy=file which sets all permissions doesnt work either. -Djava.rmi.server.codebase=some.jar doesn't work as noted by others...Neela
P
5

I'm fairly certain that you'll have to start your RMI server using the same classpath as your application. I believe it takes the same parameters as java, i.e. -cp [your class path].

Planish answered 21/1, 2009 at 10:36 Comment(1)
When you say RMI server do you mean the rmiregistry application or the server component of the application vs the client component?Demmer
A
3

I upgraded from JDK1.6.0_33 to 1.7.0_45 and had the same problem. I found this document and resolved the problem by starting rmiregistry with:

rmiregistry -Djava.rmi.server.useCodebaseOnly=false

Refer below http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html

Astigmatism answered 9/11, 2013 at 14:52 Comment(1)
Although this is the command provided in the linked article, it doesn't work as written. The property must be specified via -J-D, not just -D.Gink
D
3

Close the cmd window where the rmiregistry was initially started.In a fresh cmd go to the location where your project classfiles are located(uptill bin) and start the registry using the below command:

rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false

If you are using Eclipse ,Run the ServerSideProject and your ImplementationClass Instance gets bound to the URL specified.

Just print a line below the the binding method and see to it whether it is gets printed. If it gets printed successfully it means your server is working fine.

Dorcas answered 19/4, 2016 at 10:7 Comment(0)
P
2

try to add /bin at the end of your VM Arg:

-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008/bin

The file you will run are in this directory, so you need to include it in the path.

Powerless answered 26/11, 2010 at 10:20 Comment(1)
There is no evidence In the question about the class files being in the bin directory.Premiership
K
2

I had the same problem, to fix this ensure that your CLASSPATH is set to the path containing the server classes when running rmiregistry.

On a linux machine run the following commands.

export CLASSPATH="<server_class_path>"

Ensure the CLASSPATH has been set:

echo $CLASSPATH

Once the class path has been set, run rmiregistry

rmiregistry &
Kronos answered 7/11, 2015 at 23:7 Comment(0)
T
1

I spent a whole day uninstalling and reinstalling my JDK and changing the classpaths's and environment variables. But the culprit was that the command start rmigregistry didnt' start rmiregistry in a proper way. So, thanks for the comments on this page the solution was to unset the CLASSPATH temporarily. And that is done through the command set CLASSPATH=

Termitarium answered 10/3, 2012 at 19:30 Comment(1)
Doesn't start it 'in the proper way' for you, using your CLASSPATH, which it can't know in advance. Getting that right is up to you. Don't blame the tools.Premiership

© 2022 - 2024 — McMap. All rights reserved.