server compliation problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    server compliation problem

    when i try to compile my server i get the following errors

    D:\JAVA_P~1\SIM PLE~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 PhoneDirInterfa ce
    implements PhoneDirInterfa ce {
    ^
    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
    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, ready for action..." ); 
        }
        catch ( Exception exception ) {
          exception.printStackTrace ();
        }
      } 
    }
    they are all in the same directory ..
    PhoneDirImpl.ja va
    PhoneDirInterfa ce.java
    PhoneDirServer. java
  • rsrinivasan
    New Member
    • Mar 2007
    • 221

    #2
    Originally posted by oll3i
    when i try to compile my server i get the following errors

    D:\JAVA_P~1\SIM PLE~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 PhoneDirInterfa ce
    implements PhoneDirInterfa ce {
    ^
    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
    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, ready for action..." ); 
        }
        catch ( Exception exception ) {
          exception.printStackTrace ();
        }
      } 
    }
    they are all in the same directory ..
    PhoneDirImpl.ja va
    PhoneDirInterfa ce.java
    PhoneDirServer. java
    Hi,
    What is the problem you hava is you did not store the file in correct folder.

    If all are in the same directory then create one folder "PhoneDirectory " and store the file "PhoneDirImpl.j ava" in it. And compile the file "PhoneDirImpl.j ava" which is stored in that folder. After that compile your main program. You will get the output as you expected. Do the same thing for "PhoneDirInterf ace.java".

    And reply what happen...

    Thanks and Regards,
    Srinivasan r.
    Last edited by rsrinivasan; May 16 '07, 01:17 PM. Reason: Correction

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      D:\JAVA_P~1\SIM PLE~1\PHONED~1> javac -classpath . PhoneDirImpl.ja va
      PhoneDirImpl.ja va:34: class, interface, or enum expected
      }
      ^
      1 error

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by oll3i
        D:\JAVA_P~1\SIM PLE~1\PHONED~1> javac -classpath . PhoneDirImpl.ja va
        PhoneDirImpl.ja va:34: class, interface, or enum expected
        }
        ^
        1 error
        Good; now at least javac can find the correct source. The above is simply
        a compilation error (missing brackets etc.) Learn how to read compiler error
        diagnostic messages.

        The compiler expected something more following that right curly brackets
        which indicates that your brackets don't match properly.

        kind regards,

        Jos

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          yes you are right that was a bracket (one too many)
          i corrected it and now i get

          D:\JAVA_P~1\SIM PLE~1\PHONED~1> javac -classpath . PhoneDirImpl.ja va
          PhoneDirImpl.ja va:16: cannot find symbol
          symbol: class PhoneDirInterfa ce
          implements PhoneDirInterfa ce {
          ^
          Note: PhoneDirImpl.ja va uses unchecked or unsafe operations.
          Note: Recompile with -Xlint:unchecked for details.
          1 error

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by oll3i
            yes you are right that was a bracket (one too many)
            i corrected it and now i get

            D:\JAVA_P~1\SIM PLE~1\PHONED~1> javac -classpath . PhoneDirImpl.ja va
            PhoneDirImpl.ja va:16: cannot find symbol
            symbol: class PhoneDirInterfa ce
            implements PhoneDirInterfa ce {
            ^
            Note: PhoneDirImpl.ja va uses unchecked or unsafe operations.
            Note: Recompile with -Xlint:unchecked for details.
            1 error
            Did you successfully compile PhoneDirInterfa ce first?

            Comment

            • oll3i
              Contributor
              • Mar 2007
              • 679

              #7
              yes i did .

              Comment

              • oll3i
                Contributor
                • Mar 2007
                • 679

                #8
                why it can not find it?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by oll3i
                  why it can not find it?
                  You have

                  Code:
                   import PhoneDirectory.PhoneDirImpl;
                  But you said they are in the same directory?

                  Comment

                  • oll3i
                    Contributor
                    • Mar 2007
                    • 679

                    #10
                    server is in a Simple_RMI directory then
                    PhoneDirImpl.ja va and PhoneDirInterfa ce.java are in a subfolder of Simple_RMI which i named PhoneDirectory but i have problems now with compiling PhoneDirImpl.ja va

                    the server compiles .... i dont know what it means " unchecked or unsafe operations"

                    D:\JAVA_P~1\SIM PLE~1>javac -classpath . PhoneDirServer. java
                    Note: .\PhoneDirector y\PhoneDirImpl. java uses unchecked or unsafe operations.
                    Note: Recompile with -Xlint:unchecked for details.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by oll3i
                      server is in a Simple_RMI directory then
                      PhoneDirImpl.ja va and PhoneDirInterfa ce.java are in a subfolder of Simple_RMI which i named PhoneDirectory but i have problems now with compiling PhoneDirImpl.ja va

                      the server compiles .... i dont know what it means " unchecked or unsafe operations"

                      D:\JAVA_P~1\SIM PLE~1>javac -classpath . PhoneDirServer. java
                      Note: .\PhoneDirector y\PhoneDirImpl. java uses unchecked or unsafe operations.
                      Note: Recompile with -Xlint:unchecked for details.
                      Unsafe operations are all about generics where you use the 'raw' class while
                      the method wants a generified class. On another note: do you use the directory
                      structure I told you about (in another thread somewhere)?

                      kind regards,

                      Jos

                      Comment

                      • oll3i
                        Contributor
                        • Mar 2007
                        • 679

                        #12
                        yes
                        this is my second approach to rmi have two tutorials i found on the net
                        and two are different one implements Impl(there are methods form the interface implemented) and in the other the author adds the methods defined in the interface to the server i dont know now which way is the right one ?

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by oll3i
                          yes
                          this is my second approach to rmi have two tutorials i found on the net
                          and two are different one implements Impl(there are methods form the interface implemented) and in the other the author adds the methods defined in the interface to the server i dont know now which way is the right one ?
                          There is no single correct way: RMI is all about passing parameters over the
                          wire, invoking a method on the remote machine and passing return values
                          back again. The client just sees a 'stub' which acts as a proxy for the real
                          thing at the other side of the wire. The stubs are generated by the rmic compiler.

                          Of course the correct classes should be reachable by the local and/or remote
                          machine.

                          kind regards,

                          Jos

                          Comment

                          • oll3i
                            Contributor
                            • Mar 2007
                            • 679

                            #14
                            i took it from a different angle i added the methods form interface to the server
                            Code:
                            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 now i get

                            D:\JAVA_P~1\SIM PLE~2>rmic -classpath . -iiop -idl PhoneDirServer
                            error: java.rmi.server .RemoteServer is not a valid remote implementation: has no
                            remote interfaces.
                            1 error

                            Comment

                            • oll3i
                              Contributor
                              • Mar 2007
                              • 679

                              #15
                              i removed extends UnicastRemoteOb ject from the server
                              the server compiled but when i run it i get
                              D:\JAVA_P~1\SIM PLE~2>java PhoneDirServer
                              Exception in thread "main" java.rmi.Marsha lException: error marshalling argument
                              s; nested exception is:
                              java.io.NotSeri alizableExcepti on: PhoneDirServer
                              at sun.rmi.registr y.RegistryImpl_ Stub.bind(Unkno wn Source)
                              at java.rmi.Naming .bind(Naming.ja va:111)
                              at PhoneDirServer. main(PhoneDirSe rver.java:62)
                              Caused by: java.io.NotSeri alizableExcepti on: PhoneDirServer
                              at java.io.ObjectO utputStream.wri teObject0(Objec tOutputStream.j ava:1156)

                              at java.io.ObjectO utputStream.wri teObject(Object OutputStream.ja va:326)
                              ... 3 more

                              Comment

                              Working...