Results 1 to 5 of 5
  1. #1
    arcelivez is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default Linux running/compiling from Command Line?

    Hi,

    Well when i try to run class files with java I get this:
    Java Code:
    arturas@Universe:~/NetBeansProjects/NTPApplication/build/classes/NTP2$ java NTPServer
    Exception in thread "main" java.lang.NoClassDefFoundError: NTPServer (wrong name: NTP2/NTPServer)
    	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)
    Could not find the main class: NTPServer. Program will exit.
    When I try compiling with javac I get:
    Java Code:
    arturas@Universe:~/NetBeansProjects/NTPApplication/src/NTP2$ javac NTPServer.java 
    NTPServer.java:33: cannot find symbol
    symbol  : class NTPThread
    location: class NTP2.NTPServer
                new NTPThread(serverSocket.accept(), instanceNr).start();
                    ^
    1 error
    That's sad, I never succeeded runing JAVA apps from command line, I need somebody to teach me please...

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: Linux running/compiling from Command Line?

    NoClassDefFoundError: NTPServer (wrong name: NTP2/NTPServer)
    The class name includes a package. Include the package name with the classname:
    java NTP2.NTPServer

    Be sure to have the classpath point to the folder that contains the NTP2 folder.

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Linux running/compiling from Command Line?

    even if he gets compiler errors? ....
    looks for me more that the compiler can find the NTPThread class....
    NTPServer.java:33: cannot find symbol
    symbol : class NTPThread
    location: class NTP2.NTPServer
    new NTPThread(serverSocket.accept(), instanceNr).start();

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

    Default Re: Linux running/compiling from Command Line?

    even if he gets compiler errors? ..
    The first error message says that the java command found a class file but it had the wrong classname.

    I didn't address the second problem which looks like a missing class definition problem. That would probably be a classpath problem also with the packages part of it.

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Linux running/compiling from Command Line?

    To add to what Norm said... you typed this:

    Java Code:
    arturas@Universe:~/NetBeansProjects/NTPApplication/build/classes/NTP2$ java NTPServer
    The default classpath (in the $CLASSPATH environment variable) includes the current directory. The error message you got means that java found the file NTPServer.class in the current directory, and so expected the class in that file to be called NTPServer. But it was called NTP2.NTPServer.

    From that same prompt, you could have typed this:

    Java Code:
    cd ..
    java NTP2.NTPServer
    That would have given you the result you expected. Or you could have typed this:

    Java Code:
    java -cp .. NTP2.NTPServer
    It's been forever since I compiled on the command line. I think javac has the same -cp switch.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Problem compiling from command line
    By ande3674 in forum New To Java
    Replies: 3
    Last Post: 04-04-2011, 12:47 AM
  2. Java command line Windows vs Linux
    By shahrukh in forum New To Java
    Replies: 2
    Last Post: 01-16-2011, 05:52 PM
  3. Compiling java code from the command line
    By alman9898 in forum New To Java
    Replies: 5
    Last Post: 10-13-2010, 03:35 AM
  4. Compiling/Running in Command Prompt
    By coke_in_a_can in forum New To Java
    Replies: 12
    Last Post: 05-31-2010, 09:05 AM
  5. Replies: 1
    Last Post: 06-30-2009, 02:32 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
  •