Results 1 to 5 of 5
  1. #1
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Cannot run on server

    Hi,

    I am trying to do a basic networking. Both client and server programs work when I run them in IDE on my local machine. However, when I upload my server code (NetworkingServer.class) to the server (Debian with openjdk) and try to run it with "java NetworkingServer" I get these errors:

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: NetworkingServer (wrong name: networkingserver/NetworkingServer)
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    	at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
    Could not find the main class: NetworkingServer. Program will exit.
    The code:

    Java Code:
    package networkingserver;
    
    import java.net.*;
    import java.io.*;
    
    public class NetworkingServer {
        
        public static void main(String[] args) throws IOException {
    
            ServerSocket serverSocket = null;
            Socket clientSocket = null;
            
            try {
                serverSocket = new ServerSocket(4444);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 4444");
                System.exit(1);
            }
            
            try {
                clientSocket = serverSocket.accept();
            } catch (IOException e) {
                System.err.println("Accept failed.");
                System.exit(1);
            }
    
            clientSocket.close();
            serverSocket.close();
            
        }
        
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Cannot run on server

    java.lang.NoClassDefFoundError: NetworkingServer (wrong name: networkingserver/NetworkingServer)
    The class is in a package: networkingserver. Wherever you specify the class name you need to include the package in the name.
    Or remove the class from the package.

  3. #3
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Re: Cannot run on server

    Wherever you specify the class name you need to include the package in the name.
    What do you mean, exactly?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Cannot run on server

    I don't know how you configure the server. If there is a place for you to enter a class name, use the full class name that includes the package:
    For example: classname=thepackage.TheClass

    There is some code trying to load your class that only uses: TheClass, it should use thepackage.TheClass
    That is what the error message is saying. It read the class file and found the classname included a packagename but that packagename was not included.

    Sometimes it is simpler to remove the package statement from your source.

  5. #5
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Re: Cannot run on server

    Ok, I think I get it know. I just remove the package name and have been able to run it without any problems. Thank you for you help :).

Similar Threads

  1. Replies: 6
    Last Post: 12-26-2011, 12:33 AM
  2. from local server to remote server
    By IDH in forum Java Servlet
    Replies: 1
    Last Post: 03-24-2011, 10:05 AM
  3. Ping a server when server is not in the localhost..
    By kshitiz in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 10:17 PM
  4. smtp server configuration with jboss server
    By vilas_patil in forum Java Servlet
    Replies: 0
    Last Post: 01-05-2009, 02:18 PM
  5. Does any file in an FTP server ends up in an HTTP server?
    By islamfunny in forum CLDC and MIDP
    Replies: 4
    Last Post: 08-15-2008, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •