10/3/08

Java RMI and exceptions

Hello everyone. I know I had a lot of time to post in my blog but I was too busy. Sorry about that.

Now in this post I want to post some exceptions I had during trying to test an RMI application I was programming. I will post it as soon as I finish.

Firstly I wrote a policy file:

grant {
permission java.security.AllPermission;
};

and saved it in the same directory as policy.all
REMEMBER: I just wanted to test my application. This policy file should only be used for testing and not deployed.
I have all java files for this application in the folder C:\myRMIApp
I opened a console window and typed

cd C:\myRMIApp
javac *.java

After that I had all the classes files.
To run myapp I typed

java -Djava.security.policy=policy.all myRMIApp

where myRMIApp is the name of the class with main().
I got the following exception:

java.rmi.ConnectException: Connection refused to host: 127.0.0.1;
nested exception is:
java.net.ConnectException: Connection refused: connect

So I remembered that I had to run rmiregistry (I don't comment this :-P)
And this is what I did. I opened another console and executed rmiregistry. (I could use rmiregistry & in the same console)
Anw rmiregistry was running and I tried again to run my application so I typed the same command as above but I got another exception:

java.rmi.ServerException: RemoteException
java.rmi.UnmarshalException: error unmarshalling argument
nested exception is: java.lang.ClassNotFoundException:
myRMIAppServerInterface

I was looking my code for mistakes but I couldn't find anything wrong.
After a while I thought to try again with a little difference.
I executed rmiregistry form the C:\myRMIApp

For my big surprise this solved the above exception and I was able to test my application.
I looked the web but nobody else said that he solved this exception by running rmiregistry in the same directory so I decided to post it and probably help some people ou there having the same problem.
Thank you for visiting and reading. I'm waiting for your comments.
Del.icio.us

No comments:

Related Posts Plugin for WordPress, Blogger...