rmi compliation problem
when i try to compile my server i get the following errors
D:\JAVA_P~1\SIMPLE~1>javac -classpath . PhoneDirServer.java
PhoneDirServer.java:6: package PhoneDirectory does not exist
import PhoneDirectory.PhoneDirImpl;
^
.\PhoneDirImpl.java:34: class, interface, or enum expected
}
^
.\PhoneDirImpl.java:12: cannot find symbol
symbol: class PhoneDirInterface
implements PhoneDirInterface {
^
PhoneDirServer.java:29: cannot access PhoneDirImpl
bad class file: .\PhoneDirImpl.java
file does not contain class PhoneDirImpl
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
PhoneDirImpl myObject = new PhoneDirImpl();
^
4 errors
here is my server code
import java.util.Properties;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import PhoneDirectory.PhoneDirImpl;
/**
* Creates a Server and binds the RMI Servant with the IIOP Registry
*
*
*
*/
publicclass PhoneDirServer{
staticfinal String CONTEXT_NAME ="java.naming.factory.initial";
staticfinal String IIOP_STRING ="com.sun.jndi.cosnaming.CNCtxFactory";
staticfinal String URL_NAME ="java.naming.provider.url";
staticfinal String IIOP_URL_STRING ="iiop://localhost:1000";
/**
* Entry Point to this application
*/
publicstaticvoid main(String[] args){
try{
// Create the Object
PhoneDirImpl myObject =new PhoneDirImpl();
// Create the IIOP Initial Context
Properties iiopProperties =new Properties();
iiopProperties.put( PhoneDirServer.CONTEXT_NAME,
PhoneDirServer.IIOP_STRING );
iiopProperties.put( PhoneDirServer.URL_NAME,
PhoneDirServer.IIOP_URL_STRING );
InitialContext iiopContext =new InitialContext( iiopProperties );
// Bind the object to the IIOP registry
iiopContext.rebind("Phone Directory", myObject );
System.out.println("Hello from server, ready for action..." );
}
catch ( Exception exception ){
exception.printStackTrace ();
}
}
}
they are all in the same directory ..
PhoneDirImpl.java
PhoneDirInterface.java
PhoneDirServer.java
[3627 byte] By [
oll3ia] at [2007-11-27 4:33:04]

# 1
> they are all in the same directory ..and is that directory called ./PhoneDirectory ? and do the class all contain the statement 'package PhoneDirectory;'?If not, make it so.
ejpa at 2007-7-12 9:42:53 >

# 2
i took it form a different angle (because i found a different tutorial ,by David Reilly)
i added the methods defined in the interface to the server
i compiled the server
then i wanted to compile it with rmic to get the stubs
and it returned an error
D:\JAVA_P~1\SIMPLE~2>rmic -classpath . -iiop -idl PhoneDirServer
error: java.rmi.server.RemoteServer is not a valid remote implementation: has no
remote interfaces.
1 error
# 3
Are you serious? If you're not going to answer the questions you're asked by people who are trying to help you, or provide the source code that is causing the problem, what pray tell is the point in posting?
FYI that person's writings are many years old, and they were never reliable in the first place.
ejpa at 2007-7-12 9:42:53 >

# 4
sorry the code is
import java.rmi.*;
import java.rmi.server.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
public class PhoneDirServer extends UnicastRemoteObject
implements PhoneDirInterface {
private Map pbMap = new HashMap();
public PhoneDirServer () throws RemoteException
{
super();
try {
BufferedReader br = new BufferedReader(new FileReader("numbers.txt"));
String line;
while ((line = br.readLine()) != null)
{
String[] info = line.split(":", 2);
pbMap.put(info[0], info[1]);
}
}
catch (Exception exc) {
exc.printStackTrace();
System.exit(1);}
}
public String getPhoneNumber(String name) {
return (String) pbMap.get(name); }
public boolean addPhoneNumber(String name, String num) {
if (pbMap.containsKey(name)) return false;
pbMap.put(name, num);return true; }
public boolean replacePhoneNumber(String name, String num) {
if (!pbMap.containsKey(name)) return false;
pbMap.put(name, num);return true;
}
public static void main ( String args[] ) throws Exception
{
// Assign a security manager, in the event that dynamic
// classes are loaded
if (System.getSecurityManager() == null)
System.setSecurityManager ( new RMISecurityManager() );
// Create an instance of our service server ...
PhoneDirServer server = new PhoneDirServer();
// ... and bind it with the RMI Registry
Naming.bind ("PhoneBook",server);
System.out.println ("Service bound....");
}
}
and the interface is
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* This is an interface to a component that looks up
*
*/
public interface PhoneDirInterface extends Remote {
public String getPhoneNumber(String name) throws RemoteException;
public boolean addPhoneNumber(String name, String num) throws RemoteException;
public boolean replacePhoneNumber(String name, String num)throws RemoteException;
}
# 5
A remote object to be compiled with rmic -iiop cannot extend UnicastRemoteObject or RemoteServer.
ejpa at 2007-7-12 9:42:53 >

# 6
this would mean that the tutorial is not well written :(
because in the tutorial Server extends UnicastRemoteObject
i removed UnicastRemoteObject
but when i run the server i get
D:\JAVA_P~1\SIMPLE~2>java PhoneDirServer
Exception in thread "main" java.rmi.MarshalException: error marshalling argument
s; nested exception is:
java.io.NotSerializableException: PhoneDirServer
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at java.rmi.Naming.bind(Naming.java:111)
at PhoneDirServer.main(PhoneDirServer.java:62)
Caused by: java.io.NotSerializableException: PhoneDirServer
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
... 3 more
# 7
> this would mean that the tutorial is not well written :(
I didn't exactly say it was, but it is obvious from the code that the tutorial doesn't use rmic -iiop. If you want to use RMI/IIOP find a relevant tutorial, dont' use this one. When you use RMI/IIOP you don't use Naming.bind() for a start.
> java.io.NotSerializableException:
> PhoneDirServer
An RMI/IIOP server needs to either extend PortableRemoteObject or call PortableRemoteObject.exportObject() on construction.
ejpa at 2007-7-12 9:42:53 >

# 8
i compiled everything there was no errors
but when i run the server i opens and then shuts down :(
and when i run the client i get :((
D:\JAVA_P~1\SIMPLE~1>java -classpath . RMIClient.RMIClient
javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingCo
ntextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.j
ava:44)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:484)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:523)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:501)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at RMIClient.RMIClient.main(RMIClient.java:41)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNamin
g/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHe
lper.java:72)
at org.omg.CosNaming._NamingContextExtStub.resolve(_NamingContextExtStub
.java:406)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:470)
... 4 more
# 9
If the server had shut itself down what exactly was the point in running the client? What did you expect to get other than an exception?The important question at the moment is why did the server shutdown?One thing at a time.
ejpa at 2007-7-12 9:42:53 >

# 10
here is the server code
import java.util.Properties;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import PhoneDirectory.PhoneDirImpl;
/**
* Creates a Server and binds the RMI Servant with the IIOP Registry
*
*
*/
public class PhoneDirServer {
static final String CONTEXT_NAME = "java.naming.factory.initial";
static final String IIOP_STRING = "com.sun.jndi.cosnaming.CNCtxFactory";
static final String URL_NAME = "java.naming.provider.url";
static final String IIOP_URL_STRING = "iiop://localhost:1000";
/**
* Entry Point to this application
*/
public static void main(String[] args) {
try {
// Create the Object
PhoneDirImpl myObject = new PhoneDirImpl();
// Create the IIOP Initial Context
Properties iiopProperties = new Properties();
iiopProperties.put( PhoneDirServer.CONTEXT_NAME,
PhoneDirServer.IIOP_STRING );
iiopProperties.put( PhoneDirServer.URL_NAME,
PhoneDirServer.IIOP_URL_STRING );
InitialContext iiopContext = new InitialContext( iiopProperties );
// Bind the object to the IIOP registry
iiopContext.rebind( "Phone Directory", myObject );
System.out.println( "Hello from server");
}
catch ( Exception exception ) {
exception.printStackTrace ();
}
}
}
# 11
sigh, thank you, what happened when you ran it?
ejpa at 2007-7-12 9:42:53 >

# 12
i have no idea why it shuts down
# 13
> i have no idea why it shuts down
You mean it exits silently with no exception being thrown? I find that hard to believe. Probably you're ignoring an exception somewhere. This is bad practice wherever encountered.
> iiop://localhost:1000
Do you have an orbd running on port 1000?
ejpa at 2007-7-12 9:42:53 >

# 14
it closes too fast so i can not read what i throws:(