我已经编译了一个类并且文件显示了,但是我不能用 java 运行它或从其他类中使用它,其中 java 或 javac 的行为就好像它不存在一样。
它编译...
john@fekete:~/devel/java/mysqlexample$ javac first/mysql/MySQLAccess.java
Note: first/mysql/MySQLAccess.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
它似乎不存在于java...
john@fekete:~/devel/java/mysqlexample$ java first/mysql/MySQLAccess.class
Error: Could not find or load main class first.mysql.MySQLAccess.class
john@fekete:~/devel/java/mysqlexample$ java first/mysql/MySQLAccess
Error: Could not find or load main class first.mysql.MySQLAccess
我不能在其他课程中使用它。
first/mysql/test/Main.java:3: error: cannot find symbol
import first.mysql.MySQLAccess;
^
symbol: class MySQLAccess
location: package first.mysql
这些文件的结构就是这样,我从该结构的根目录编译。
john@fekete:~/devel/java/mysqlexample$ ls -l first/mysql/
total 12
-rwxr-xr-x 1 john john 3625 May 2 07:59 MySQLAccess.class
-rw-r--r-- 1 john john 3052 May 2 07:59 MySQLAccess.java
drwxr-xr-x 2 john john 4096 May 2 08:02 test
john@fekete:~/devel/java/mysqlexample$ ls -l first/mysql/test/
total 4
-rw-r--r-- 1 john john 205 May 2 08:02 Main.java
导入 first.mysql.* 不起作用。
也许我需要改变我的类路径。
john@fekete:~/devel/java/mysqlexample$ echo $CLASSPATH
/usr/local/mysql-connector-java/mysql-connector-java-5.1.24-bin.jar