ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[jordan@Jordan-Laptop ~]$ ls -l /usr/share/java/mysql-connector-java.jar
lrwxrwxrwx. 1 root root 31 Jun 12 18:29 /usr/share/java/mysql-connector-java.jar -> mysql-connector-java-5.1.15.jar
[jordan@Jordan-Laptop ~]$
[jordan@Jordan-Laptop ~]$ ls -lL /usr/share/java/mysql-connector-java.jar
-rwxr-xr-x. 1 root root 817285 Feb 10 02:12 /usr/share/java/mysql-connector-java.jar
[jordan@Jordan-Laptop ~]$
[jordan@Jordan-Laptop ~]$ ls -l /usr/share/java/mysql-connector-java-5.1.15.jar
-rwxr-xr-x. 1 root root 817285 Feb 10 02:12 /usr/share/java/mysql-connector-java-5.1.15.jar
I have downloaded the connector straight from the MySQL site and have tried to use that one. It works fine on Windows but I get the same Class Not Found error on my laptop running Fedora 14 and my server running Ubuntu 10.04
For Ubuntu, try using the one that comes from their repository (via Synaptic Manager) versus using the one from the MySQL website. Similarly for Fedora, you should use "yum".
If you used "ftp", for example, you need to make sure to do a binary transfer.
A shot in the dark ...
I downloaded it via HTTP, plus the jar runs just fine on Windows in the same directory as my-jar.jar
Quote:
Originally Posted by dwhitney67
For Ubuntu, try using the one that comes from their repository (via Synaptic Manager) versus using the one from the MySQL website. Similarly for Fedora, you should use "yum".
I installed the MySQL connector using the package manager of each machine and those didn't work either, got the Class Not Found Exception.
I downloaded it via HTTP, plus the jar runs just fine on Windows in the same directory as my-jar.jar
I installed the MySQL connector using the package manager of each machine and those didn't work either, got the Class Not Found Exception.
Back to the version of Java, which do you have running under the Ubuntu system?
At my home, I have Ubuntu 10.04 and 10.11; on both machines I have the openJDK installed, along with the MySQL connector, which I obtained from the package manager. On both systems, I defined the CLASSPATH as we have already discussed, and everything works fine.
If on your Ubuntu system, if you have performed any deviations from the basic steps I took, then that might explain why you are having issues. I would suggest that you remove the relevant packages in their entirety, then reinstall using the package manager.
root@ubuntu-server:/home/jordan# apt-get -qq install openjdk-6-jre-headless libmysql-java
root@ubuntu-server:/home/jordan# exit
jordan@ubuntu-server:~$ dir
public_html settings.conf my-jar.jar
jordan@ubuntu-server:~$ dir /usr/share/java/
libintl.jar mysql-5.1.10.jar mysql-connector-java-5.1.10.jar mysql-connector-java.jar mysql.jar
jordan@ubuntu-server:~$ export CLASSPATH=./:/usr/share/java/mysql-connector-java.jar; echo $CLASSPATH
./:/usr/share/java/mysql-connector-java.jar
jordan@ubuntu-server:~$ ls -l /usr/share/java/mysql-connector-java.jar
lrwxrwxrwx 1 root root 31 2011-06-14 09:54 /usr/share/java/mysql-connector-java.jar -> mysql-connector-java-5.1.10.jar
jordan@ubuntu-server:~$ ls -lL /usr/share/java/mysql-connector-java.jar
-rw-r--r-- 1 root root 754057 2010-01-26 03:02 /usr/share/java/mysql-connector-java.jar
jordan@ubuntu-server:~$ ls -l /usr/share/java/mysql-connector-java-5.1.10.jar
-rw-r--r-- 1 root root 754057 2010-01-26 03:02 /usr/share/java/mysql-connector-java-5.1.10.jar
jordan@ubuntu-server:~$ java -cp $CLASSPATH -jar ./my-jar.jar
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at Server.loadMysqlDriver(Server.java:29)
at Server.<init>(Server.java:23)
at Server.main(Server.java:42)
jordan@ubuntu-server:~$
I'm running version 6b20-1.9.7-0ubuntu1~10.04.1 of openjdk-6-jre-headless and version 5.1.10+dfsg-2ubuntu1 of libmysql-java. I may just decompress the jar and load it directly into my project and not worry about this Class Not Found nonsense
cat ./Manifest
Main-Class: Server
Class-Path: /usr/share/java/mysql-connector-java.jar
If I copy mysql-connector-java.jar into the same folder as my-jar.jar it works (which is okay I guess), but if its not, it gives the Class Not found error
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.