LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-21-2006, 04:07 PM   #1
lbyrd
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Rep: Reputation: 0
Java apps runs fine but gives error from jar file-NoClassDefFoundError


Hello,
I seem to be having a problem creating a jar file that I can use to access a mysql data base. I am using Linux Fedora Core 3, jave jdk1.5.0_04, mysql DB and the j/connector from the mysql site (mysql-connector-java-3.1.12). I have the jar file for the connector in jdk1.5.0_04/jre/lib/ext/mysql-connector-java-3.1.12-bin.jar ( am not sure that is the correct place but I have tried several different locations to no avail). I am using the eclipse IDE to create the programs and everything runs great while in the ide. Eclipse uses the directory workspace for its work area and I have created a project othertest. Here is the directory listing for that project:
bin (this is the directory where the class files are kept)
ShowWxData.jar
ShowWxData.mf
src (this is the directory where the java files are kept)

the listing for the bin directory:
>ls -1 bin
ShowWxData.class
WxStationData.class

when I cd into the bin directory and run the java program all is good:
[lbyrd@localhost bin]$ java ShowWxData
Current Conditions as of 2006-04-21 12:51:35.0
Partially Cloudy
Temperature ouside 69.3 deg F with humidity at 59%
Winds from 201 deg. at 11mph
Last wind gust from 202deg. at 13mph
Forecast: Partly cloudy with little temperature change..
+ + + + + + + + + + + + + + + + + + +

However when I move up one directory and try to use the jar file, this is what I get:
[lbyrd@localhost othertest]$ java -jar ShowWxData.jar
Exception in thread "main" java.lang.NoClassDefFoundError: ShowWxData

Here is the contents of the jar file:
>jar -tf ShowWxData.jar
META-INF/
META-INF/MANIFEST.MF
bin/ShowWxData.class
bin/WxStationData.class
/usr/java/jdk1.5.0_04/jre/lib/ext/mysql-connector-java-3.1.12-bin.jar

here is the manifest file:
cat ShowWxData.mf
Manifest-Version: 1.0
Class-Path: . /usr/java/jdk1.5.0_04/jre/lib/ext/mysql-connector-java-3.1.12-bin.jar
Main-Class: ShowWxData

What I am doing wrong so the jar file does not work. Any help/hints are greatly appreicated.

Lyman
 
Old 04-21-2006, 04:28 PM   #2
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
How did you create your jar file? Do you need a bin directory or is ShowWxData in the bin package. If the class ShowWxData is in the bin package then the main-class should be : bin.ShowWxData.

ps : You do not need to put the mysql jar in the ext directory of your java virtual machine. You could add it to your project classpath in eclipse.
 
Old 04-24-2006, 09:58 AM   #3
lbyrd
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
answer to questions

In eclipse I was exterimenting with splitting out the src and class files and that is why I have the bin directory. I have tried creating the jar file by hand and from withing eclipse with the same result. do you have a suggestion of the jar command that I should try?

I had added the mysql connectory jar file to the project which worked just fine but as I pointed out everything worked ok as long as I was running under eclipse but not from the jar file so I was trying everything I could think of to try to make it work.

Any and all suggestions are greatly appreciated.

Thanks
Lyman
 
Old 04-24-2006, 10:08 AM   #4
lbyrd
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
You had the correct idea.

After I sent the other reply I tried a little experiment. I copied all the class files from the bin directory to the current directory and created the jar file again using the command
jar -cvmf ShowWxData.mf ShowWxData.jar *.class

and guess what it all works not no matter where I move or copy the jar file...

So do most people not use the split bin and src structure? could I have done something different on in eclipse to make the jar file?

Thanks so much for the help and the mentoring...

Lyman
 
Old 04-25-2006, 12:46 PM   #5
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
When i was using eclipse i used to split src and classes directory(bin by default) and it always worked. I always used the eclipse jar export tool while specifying a main class to run.
 
Old 04-25-2006, 12:50 PM   #6
lbyrd
LQ Newbie
 
Registered: Apr 2006
Posts: 8

Original Poster
Rep: Reputation: 0
I tried eclipse export first as well

As the subject states I had tried the eclipse export tool first and that is what led me to the current problem. I still dont really understand why it didnt work. May I need to export the project ... I will try that ..

So much to learn, so little brain available...

Thanks for the help

Lyman
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run a java jar file. sabliny Programming 7 11-05-2005 02:59 PM
howto run a java.jar file in FC2-3 mickeyboa Fedora 1 02-11-2005 02:01 PM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 06:26 AM
Most Java runs fine, one game is slow Brain Drop Linux - Software 0 08-10-2004 11:10 AM
Java, code compiles and supposedly runs fine in windows, but not linux exodist Programming 4 03-16-2004 01:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:06 AM.

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