Results 1 to 5 of 5
- 01-27-2012, 01:05 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
Linux running/compiling from Command Line?
Hi,
Well when i try to run class files with java I get this:
When I try compiling with javac I get: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.
That's sad, I never succeeded runing JAVA apps from command line, I need somebody to teach me please...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
- 01-27-2012, 01:36 PM #2
Re: Linux running/compiling from Command Line?
The class name includes a package. Include the package name with the classname:NoClassDefFoundError: NTPServer (wrong name: NTP2/NTPServer)
java NTP2.NTPServer
Be sure to have the classpath point to the folder that contains the NTP2 folder.
- 01-27-2012, 01:39 PM #3
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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();
- 01-27-2012, 01:47 PM #4
Re: Linux running/compiling from Command Line?
The first error message says that the java command found a class file but it had the wrong classname.even if he gets compiler errors? ..
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.
- 01-27-2012, 11:10 PM #5
Re: Linux running/compiling from Command Line?
To add to what Norm said... you typed this:
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.Java Code:arturas@Universe:~/NetBeansProjects/NTPApplication/build/classes/NTP2$ java NTPServer
From that same prompt, you could have typed this:
That would have given you the result you expected. Or you could have typed this:Java Code:cd .. java NTP2.NTPServer
It's been forever since I compiled on the command line. I think javac has the same -cp switch.Java Code:java -cp .. NTP2.NTPServer
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Problem compiling from command line
By ande3674 in forum New To JavaReplies: 3Last Post: 04-04-2011, 12:47 AM -
Java command line Windows vs Linux
By shahrukh in forum New To JavaReplies: 2Last Post: 01-16-2011, 05:52 PM -
Compiling java code from the command line
By alman9898 in forum New To JavaReplies: 5Last Post: 10-13-2010, 03:35 AM -
Compiling/Running in Command Prompt
By coke_in_a_can in forum New To JavaReplies: 12Last Post: 05-31-2010, 09:05 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks