|
|
#1 |
|
Can't execute java from command line
Hello, I am attempting to run some java from my terminal and seems to be getting the following error:
Code:
09:44@joshMac:.+rc/edu/american$ java DataLink Exception in thread "main" java.lang.NoClassDefFoundError: DataLink Caused by: java.lang.ClassNotFoundException: DataLink at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Code:
09:46@joshMac:.+rc/edu/american$ java DataLink -cp . Also, when checking the classpath: Code:
09:50@joshMac:.+t1/edu/american$ pwd /Users/***/Documents/school/11spr/csc546/project1/edu/american 09:50@joshMac:.+t1/edu/american$ $CLASSPATH -bash: /Users/***/Documents/school/11spr/csc435/project/edu/american: No such file or directory Any help would be much appreciated. Thanks. |
|
|
|
0
|
|
|
#2 | |
|
Quote:
|
||
|
|
0
|
|
|
#3 |
|
I executed the javac and java commands from within the same directory as the pwd printed (/Users/***/Documents/school/11spr/csc546/edu/american)
It is part of a package and that could be my problem because that is really the only thing different between this and what I've done in the past. |
|
|
|
0
|
|
|
#4 | |
|
Quote:
Code:
java package.MyClass |
||
|
|
0
|
|
|
#5 |
|
Still no luck. If this is what you meant. My package is edu.american. So, I tried the following:
Code:
14:41@joshMac:.+t1/edu/american$ pwd /Users/***/Documents/school/11spr/csc546/project1/edu/american 14:41@joshMac:.+t1/edu/american$ java edu.american.DataLink Exception in thread "main" java.lang.NoClassDefFoundError: edu/american/DataLink Caused by: java.lang.ClassNotFoundException: edu.american.DataLink at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) One thing to note is these are all symbolic links Code:
-rw-r--r-- 1 *** *** 853 Mar 3 19:27 DataLink$ButtonListener.class -rw-r--r-- 1 *** *** 2422 Mar 3 19:27 DataLink.class lrwxr-xr-x 1 *** *** 85 Feb 24 22:17 DataLink.java -> /Users/***/EclipseProjects/SlidingWindowProtocol/src/edu/american/DataLink.java -rw-r--r-- 1 *** *** 6249 Mar 3 19:27 DataLinkHost.class lrwxr-xr-x 1 *** *** 89 Feb 24 22:18 DataLinkHost.java -> /Users/***/EclipseProjects/SlidingWindowProtocol/src/edu/american/DataLinkHost.java -rw-r--r-- 1 *** *** 1454 Mar 3 19:27 Wire.class lrwxr-xr-x 1 *** *** 81 Feb 24 22:18 Wire.java -> /Users/***/EclipseProjects/SlidingWindowProtocol/src/edu/american/Wire.java |
|
|
|
0
|
|
|
#6 |
|
As per normal, standard, Java rules the .class files must be in a folder hierarchy that matches the reverse DNS package.
So in this case they should be in edu/american/ relative to the current path (or relative to any path in the CLASSPATH).
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
|
|
#7 |
|
you need to have a directory structure along the lines of
Code:
.../build/edu/american/DataLink.class .../build/edu/american/etc (other class files in package Code:
/Users/***/Documents/school/11spr/csc546/build $ java edu.american.DataLink Your classpath entry needs to be: /Users/***/Documents/school/11spr/csc546/build If you are executing java from build/ you are set since . is automatically part of the classpath (unless you set the CLASSPATH environment variable otherwise). If you are not executing from build, then you need to set the classpath explicitly: Code:
java -cp /Users/***/Documents/school/11spr/csc546/build edu.american.DataLink |
|
|
|
0
|
|
|
#8 |
|
Yeah I am good to go. On top of all that I forgot I had set a classpath in my .bashrc for something...
Thanks!! |
|
|
|
0
|
|
|
#9 | |
|
Quote:
So for package a.b.c.d there should be a corresponding directory structure for source files and class files (they don't have to be the same ones), e.g. src/a/b/c/d build/a/b/c/d |
||
|
|
0
|
|
|
#10 |
|
CLASSPATH environment variable set globally is evil. Don't do it. It will cause you nothing but grief. Use projects scripts (better yet, use Apache Ant or Maven) to set classpath locally for each project.
|
|
|
|
0
|
|
|
#11 | |
|
Quote:
I realize this is an old post that I found. But for other new users out there, here is what I was able to do to get the java command to actually run the .class file. I was able to cd to the directory of my .java and .class files and run both the javac and java cammands. Once I ran the java command, my program popped up an input window just as it should have. So my terminal prompt began at (systemname:~ user$) and since my Java files are in a folder called JavaFiles, I typed this to change directory to my file location. (cd JavaFiles/Assn2) without the parenthesis of coarse. then I was able to run both the javac and the java commands just fine without getting the Exception error when running the java command. |
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Running Java program from command line | naples98 | Mac Programming | 5 | Jan 19, 2011 02:48 PM |
| Controlling the Fan...from Command Line? | Djmx | MacBook Pro | 0 | Aug 12, 2007 09:06 PM |
| Installing applications from command line | jeremy.king | Mac OS X | 5 | Jul 21, 2005 03:40 PM |
| Change desktop picture from command line ??? | JupiterZen | Mac Applications and Mac App Store | 4 | Aug 9, 2003 05:33 PM |
| here's how to burn a cd from command line | wescbrown | Mac Help/Tips | 2 | May 17, 2002 06:15 PM |
All times are GMT -5. The time now is 11:08 AM.







Linear Mode

