aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to run RMI Application in NetBeans 4.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to run RMI Application in NetBeans 4.0" Watch "How to run RMI Application in NetBeans 4.0" New topic
Author

How to run RMI Application in NetBeans 4.0

Amitav Anand
Ranch Hand

Joined: Sep 22, 2003
Posts: 46
Hi ,
I am new to RMI technology and trying to execute one small application using Netbeans IDE 4.0, but its not working ...

I have created four different files such as:
Remote_Interface.java
Remote_Interface_Impl.java
Remote_Interface_Server.java and
ClientApp.java

Everything is working fine in DOS environment using jdk1.5.0_01 without security implementation and as well as with RMI security implementation..
but unfortunately in NetBeans its not the same...

Here is the source code of the server application which is written without RMI security for your kind reference....

package myserver;
import java.rmi.*;
/**
*
* @author Administrator
*/
public class Remote_Interface_Server {

/** Creates a new instance of Remote_Interface_Server */
public Remote_Interface_Server() {
}
public static void main(String args[])
{
try{
Remote_Interface_Impl obj=new Remote_Interface_Impl();
}
Runtime.getRuntime().exec("c:/Program Files/Java/jdk1.5.0_01/bin/rmiregistry.exe");
Naming.rebind("rmi://192.168.0.15:1099/myserver",obj);
System.out.println("Server Started.............Waiting 4 Client Request");
}
catch(Exception e)
{
e.printStackTrace();

}

}
}

When I am trying to execute its throwing the following exceptions:

init:
deps-jar:
compile-single:
run-single:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: myserver.Remote_Interface_Impl_Stub
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at myserver.Remote_Interface_Server.main(Remote_Interface_Server.java:26)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: myserver.Remote_Interface_Impl_Stub
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.ClassNotFoundException: myserver.Remote_Interface_Impl_Stub
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 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
... 9 more

But I don't understand why its throwing error for Remote_Interface_Impl_Stub.class, which is already there in the NetBeans.

I created this stub using the following step in NetBeans:
This is the source of build.xml file ....

<project name="RMIServer" default="default" basedir=".">
<description>Builds, tests, and runs the project RMIServer.</description>
<import file="nbproject/build-impl.xml"/>
< !--<br /> Some comments<br /> -->
</project>

In the above file I have just added the following target between project start and end tag.

<target name="-post-compile">
<rmic base="${build.classes.dir}" includes="**/Remote_Interface_Impl*.class"/>
</target>

And its working fine and creating the Stub class at the time of building the whole project....
But the exception is thrown at the time of running the project...

I am trying to run the server application first just to test whether its working or not....

RmiRegistry program is also getting started while executing the server application....

Then I thought to implement RMISecurityManager to overcome the problem,but now its showing some differeent exceptions....

Here is the code with RMISecurity and the exceptions thrown:

package myserver;
import java.rmi.*;
/**
*
* @author Administrator
*/
public class Remote_Interface_Server {

/** Creates a new instance of Remote_Interface_Server */
public Remote_Interface_Server() {
}
public static void main(String args[])
{
try{
Remote_Interface_Impl obj=new Remote_Interface_Impl();
if(System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Runtime.getRuntime().exec("c:/Program Files/Java/jdk1.5.0_01/bin/rmiregistry.exe");
Naming.rebind("rmi://192.168.0.15:1099/myserver",obj);
System.out.println("Server Started.............Waiting 4 Client Request");
}
catch(Exception e)
{
e.printStackTrace();

}

}
}


And the exceptions :

init:
deps-jar:
compile-single:
run-single:
java.security.AccessControlException: access denied (java.io.FilePermission c:/Program execute)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkExec(SecurityManager.java:779)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:447)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:429)
at java.lang.Runtime.exec(Runtime.java:326)
at myserver.Remote_Interface_Server.main(Remote_Interface_Server.java:25)
BUILD SUCCESSFUL (total time: 1 minute 1 second)


I have also created a policy file having the name
mypolicy.policy and the content is

grant
codeBase
"file:/c:/Program Files/Java/jdk1.5.0_01/bin/"{
permission java.security.AllPermission;
};

and at the time of running the program i am passing the following option to the VM
-Djava.security.policy="C:\NetBeansProjectSrc\RMIServer\src\myserver\
mypolicy.policy"

I am trying to implement this small application since last three days...

Please help me out in this regard....

Thanking all of u in advance....

Please help .....


anxiously waiting ..

Regards

Amitav Anand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run RMI Application in NetBeans 4.0
 
Similar Threads
UnmarshalException
RMI in NetBeans 4.0
UnmarshalException while executing the Server Application
Eclipse wont run my RMI program?
cant run java file from command line but works with .sh file??