Textmate broke my Java? Exception in thread "main" java.lang.NoClassDefFoundError
I ran a Java program using TextMate on OS X once and I can't use Java anywhere else anymore.
On the simplest program, I get:Exception in thread "main" java.lang.NoClassDefFoundError: Gateway (wrong name: org/mcgill/telecom/Gateway)
Whether I use javac -classpath . Gateway.java, java -classpath . Gateway
or Eclipse or N开发者_如何学Goetbeans.
The exact same program can still run in TextMate using cmd-R, but nowhere else.
What happened to my Java?I highly doubt that a text editor did that.
Anyway, java -classpath . Gateway
wouldn't work if that class is in the package org.mcgill.telecom
(which the folder structure suggests).
Try java -classpath . org.mcgill.telecom.Gateway
instead from the folder where the org
folder can be seen.
Here's what you can do to test it.
- go to a
temp
folder and create this folder structure:org/mcgill/telecom
; - create a file called
Gateway.java
in thetelecom
folder; - copy the contents below in your
Gateway.java
file; - open a command prompt and navigate to your
temp
folder; - execute
javac org/mcgill/telecom/Gateway.java
- execute
java -classpath . org.mcgill.telecom.Gateway
This is what I get:
bart@hades:~$ cd Temp/
bart@hades:~/Temp$ ls
org
bart@hades:~/Temp$ javac org/mcgill/telecom/Gateway.java
bart@hades:~/Temp$ java -classpath . org.mcgill.telecom.Gateway
Oi, it works!
bart@hades:~/Temp$
Here the Gateway class:
package org.mcgill.telecom;
public class Gateway {
public static void main(String[] args) {
System.out.println("Oi, it works!");
}
}
精彩评论