user2071938
user2071938

Reputation: 2265

Class.forName(“com.mysql.jdbc.Driver”) does not work on Raspberry Pi

this code:

        Class.forName("com.mysql.jdbc.Driver"); 

leads to an

ClassNotFoundException

on raspberry Pi. although my Classpath is correct

pi@raspberrypi ~ $ echo $CLASSPATH
/usr/share/java/mysql-connector-java.jar

on Windows it just works fine! any idea what I'm doing wrong?

I also tried to start my Application with

java -cp /usr/share/java/mysql-connector-java.jar -jar myApp.jar

thanks florian

Upvotes: 0

Views: 2790

Answers (2)

jmail
jmail

Reputation: 6132

Just copy the MySql-Connector.jar in apache tomcat's lib folder and then remove the jar in project's lib folder and then, run the project.

What did you put exactly in lib, jre/lib or jre/lib/ext? Was it the jar mysql-connector-java-5.1.5-bin.jar or something else (like a directory)?

By the way, I wouldn't put it in lib, jre/lib or jre/lib/ext, there are other ways to add a jar to the classpath. You can do that by adding it explicitly the CLASSPATH environment variable. Or you can use the -cp option of java.

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1503459

You're using -jar, which makes the -cp part irrelevant. From the documentation:

When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.

Either add ClassPath entries in your jar manifest, or add the MySQL connector jar file to an extension directory (e.g. jre/lib/ext). Using the manifest is the cleanest approach though.

Upvotes: 4

Related Questions