LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-25-2012, 07:05 AM   #1
sbutt
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Rep: Reputation: Disabled
setting classpath for mysql java connector in linux


Hi All,
I have a simple java application which reads data from the DB. The application works fine on windows. I have added the 'mysql-connector-java-5.1.22-bin.jar' in my windows classpath.
The problem comes when i copy the application on linux and run it. I getthe following exception:

Code:
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
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.ClassLoader.loadClassInternal(ClassLoader.java:334)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at LCPAnalyzer.connectDB(LCPAnalyzer.java:47)
at LCPAnalyzer.main(LCPAnalyzer.java:32)
I have read various articles on setting classpath in linux, but couldn't get through and I am still unclear as to how to set the classpath in linux?

I even copied the 'mysql-connector-java-5.1.22-bin.jar' in my project src folder where the .class file is generated but still no success.

I also tried setting the classpath at runtime by: export CLASSPATH=/opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar

but then i got the follwoing exception:

Code:
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# javac LCPAnalyzer.java
root@HH-Linux1:/opt/integra/middleware/LCPAnalyzer/src# java LCPAnalyzer
Exception in thread "main" java.lang.NoClassDefFoundError: LCPAnalyzer
Caused by: java.lang.ClassNotFoundException: LCPAnalyzer
I am totally lost as how to proceed now. Could someone please suggest a permanent way to set classpath in linux. I have few other java mail api related jars as well, which i would want to set in the classpath in linux but first want to resolve this mysql connector problem.

Any help woudl really be appreciated.

Thanks
 
Old 09-26-2012, 09:54 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
When you didn't set the CLASSPATH, and didn't use a corresponding command line argument to the Java run time ( JVM ), the mysql driver class could not be found. When you set the CLASSPATH incorrectly, including just the driver jar, the Java program you had compiled and then were trying to run, could not be found because you didn't include the current directory on the CLASSPATH. Multiple items can be put on the CLASSPATH each separated from the other by a colon.

Code:
export CLASSPATH=/opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar:.
The CLASSPATH value can be set in a shell start up file, such as by placing the export command in the file .profile for Bourne-shell style shells, or .bash_login or .bash_profile if you want something specifically for the BASH shell.
 
Old 09-27-2012, 05:24 AM   #3
sbutt
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kakaka View Post
When you didn't set the CLASSPATH, and didn't use a corresponding command line argument to the Java run time ( JVM ), the mysql driver class could not be found. When you set the CLASSPATH incorrectly, including just the driver jar, the Java program you had compiled and then were trying to run, could not be found because you didn't include the current directory on the CLASSPATH. Multiple items can be put on the CLASSPATH each separated from the other by a colon.

Code:
export CLASSPATH=/opt/integra/middleware/LCPAnalyzer/src/mysql-connector-java-5.1.22-bin.jar:.
The CLASSPATH value can be set in a shell start up file, such as by placing the export command in the file .profile for Bourne-shell style shells, or .bash_login or .bash_profile if you want something specifically for the BASH shell.
Thanks, I got that figured out already!
 
Old 09-27-2012, 04:27 PM   #4
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Quote:
Originally Posted by sbutt View Post

[...]

Thanks, I got that figured out already!
If you've solved your own problem, then please mark the thread as solved. That let's people who wish to help solve problems know that they need not view your thread, and those that are looking for a solution to a problem such as the one you experienced, know where they can find the solution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql and mysql java connector, connection refused arubin Slackware 3 03-29-2008 01:41 AM
Setting java classpath in slackware12 MarkSlack Slackware 1 12-17-2007 07:02 AM
Setting up my java classpath in redhat working2hard Programming 9 07-28-2004 10:15 AM
setting classpath for java in mdk9.2 perryub Linux - Newbie 2 05-07-2004 04:02 PM
setting java classpath... brutal_brad Linux - Newbie 7 09-21-2003 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration