The Artima Developer Community
Sponsored Link

Java Answers Forum
Sending and running a Java program on a remote computer

19 replies on 2 pages. Most recent reply: Jul 31, 2005 5:41 PM by MS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 19 replies on 2 pages [ « | 1 2 ]
MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 19, 2005 11:48 AM
Reply to this message Reply
Advertisement
Hey guys,

Reflection API's worked beautifully.. Thanks! :-)

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 29, 2005 7:45 PM
Reply to this message Reply
Hi again,

It's odd, but I often get an error. Here's the Server program.. but I doubt you need to read it all. Please just scroll down to "
// The line below is what give me problems:
".

package remoterun;
 
import java.net.*;
import java.io.*;
import java.lang.reflect.*;
 
 * <p>Copyright: Copyright ms2000 (c) 2005</p>
 
public class Server2 {
 
    public static void main(String args[]) throws Exception {
 
        int numParameters;
        int port = 6789;
        boolean isThere = false;
        String className, methodName;
        Object[] parameters;
        ServerSocket welcomeSocket = new ServerSocket(port);
 
        for (; ; ) {
 
            /**
             * Create a new socket, called connectionSocket, when some client knocks
             * on welcomeSocket. This socket has the same port number. TCP then
             * establishes a direct virtual pipe between the client socket and
             * connectionSocket at the server so the client and server can send bytes
             * to each other over it.
             */
 
            Socket connectionSocket = welcomeSocket.accept();
 
            // Get number of parameters
 
            DataInputStream in = new DataInputStream(new BufferedInputStream(
                    connectionSocket.getInputStream()));
            numParameters = in.readInt();
 
// Get the parameters for the method to be invoked.
 
            parameters = new Object[numParameters];
 
 
            ObjectInputStream objStream = new ObjectInputStream(
                    connectionSocket.getInputStream());
 
            for (int i = 0; i < numParameters; i++) {
 
                parameters[i] = objStream.readObject();
            }
 
            // read the class
            File program = (File) objStream.readObject();
 
            //Class2.test();
            //program.deleteOnExit();
 
            //connectionSocket.close();
            //welcomeSocket.close();
 
            System.err.println(program); // It prints the program name correctly, e.g. Class2.java
 
// Receiving some String parameters...
 
                        BufferedReader inFromClient = new BufferedReader(new
                    InputStreamReader(connectionSocket.getInputStream()));
 
 
            className = inFromClient.readLine();
 
            methodName = inFromClient.readLine();
 
            // The line below is what give me problems:
 
            Class classDefinition = Class.forName("remoterun." + className + ".java");
            Object object = classDefinition.newInstance();
 
            Method[] theMethods = classDefinition.getMethods();
 
            for (int i = 0; (i < theMethods.length) && (!isThere); i++) {
 
 
 
                if (theMethods[i].getName().equals(methodName)) {
 
                    isThere = true;
                    theMethods[i].invoke(object, parameters);
                }
            }
        }
 
 
    }
}
 



The error I get is:


java.lang.ClassNotFoundException: remoterun.Class2.java

at java.net.URLClassLoader$1.run(URLClassLoader.java:199)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:187)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:141)

at remoterun.Server2.main(Server2.java:94)

Exception in thread "main"


(I also get a dialog box saying sthg like, "A fatal exception occured.. will exit now".)

It's really odd, becuase there were rare times when it works although I don't change the program...

I tried changing the problem line to stuff like:

            Class classDefinition = Class.forNameclassName + ".java");


or

   Class classDefinition = Class.forName(className);


but with no use. Same error. Can someone please pinpoint the problem?

I'm sure the program does get to the Server, because it can print out the file name.

I'd appreciate some assistance in this.

Thank you.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 30, 2005 7:51 PM
Reply to this message Reply
PS: It seems to be working fine if I use a single computer as both the client and server.. but doesn't work with a remote server.. weird.

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 31, 2005 10:04 AM
Reply to this message Reply
help?

MS

Posts: 16
Nickname: ms2000
Registered: May, 2005

Re: Sending and running a Java program on a remote computer Posted: Jul 31, 2005 5:41 PM
Reply to this message Reply
Now it's not working on the local address either... great..

Flat View: This topic has 19 replies on 2 pages [ « | 1  2 ]
Topic: stacktrace for unchecked exceptions Previous Topic   Next Topic Topic: jdbc connectivity

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use