Results 1 to 8 of 8
- 12-08-2008, 01:39 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 6
- Rep Power
- 0
JDBC Driver errors in command line but not NetBeans
Hello,
I have a java application which I built with NetBeans 6.1 which connects to a MySql DB. When I run the application using F6 in NetBeans, everything runs correctly.
However, when I run the application through the command line with this command:
java -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"
I get the following error:
java.lang.noclassdeffounderror: com/mysql/jdbc/Connection
I believe this is to do with a jar file minssing from the classpath. However, my classpath includes the location of the jar:
.;C:\niall\Java\jdk1.6.0_02;C:\mysql-connector-java-3.0.17-ga\mysql-connector-java-3.0.17-ga-bin.jar
I have also tried to run the program on the command line with the following commands, both give the same werror as above:
java -jar C:\path to my sql jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"
Any help would be greatly appreciated.
- 12-08-2008, 01:40 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because you need to include the Driver jarfile on the classpath (use the -cp option). What you configure in NetBeans has no influence on what happens outside of NetBeans.
- 12-08-2008, 02:40 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 6
- Rep Power
- 0
Hello Masijade, Thanks for you reply.
Do You mean:
java -jar C:\mysql-connector-java-5.0.7-bin.jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"
?
I have tried this and the same error occurs.
- 12-08-2008, 02:44 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
If you are going to use the -jar option, then you will have to configure the Classpath in the manifest file. What I said, was to use the -cp option.
See
Working with Manifest Files: The Basics (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
and
java - the Java application launcher
- 12-08-2008, 04:46 PM #5
Member
- Join Date
- Oct 2008
- Posts
- 6
- Rep Power
- 0
I have looked at these sites and havent found a lead to a solution in either.
Any other ideas?
- 12-08-2008, 05:10 PM #6
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
option 1
open command prompt
java -cp C:\mysql-connector-java-5.0.7-bin.jar -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"
option 2
open command prompt
set classpath=%classpath%;C:\mysql-connector-java-5.0.7-bin.jar
java -jar "C:\niall\RTN\dist\RTN_Report_Manager.jar"
option 3
extract the RTN_Report_Manager.jar and open manifest.mf
check the value of Main-Class
open command prompt
set classpath=%classpath%;C:\mysql-connector-java-5.0.7-bin.jar;C:\niall\RTN\dist\RTN_Report_Manager.jar
java <Main-Class>
- 12-08-2008, 05:57 PM #7
Member
- Join Date
- Oct 2008
- Posts
- 6
- Rep Power
- 0
Hello W3User,
Thanks for your help. I had already tried The first two options but had no luck. Using both returs the same java.lang error as stated in my first post.
As for the third option, when tried, it
doesnt work either. It advises that it cant find the main class.
- 12-08-2008, 06:20 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
With the -jar option both the system classpath and the -cp option is ignored. (as the second provided link explains) so you have to designate the classpath in the manifest file (as the first link explained). And using the -cp option means the System classpath with ignored. As you can see both option 1 and 2 above are completely invalid. And option 3, while peripherally correct, should have used the -cp option, rather than the system classpath, and should have spelled out that you need to reference your mainclass using the entire package path.
Option 1 : set the classpath in the manifest file, and then
See the first link (and the second).Java Code:java -jar c:/full/path/to/your/jarfile.jar
Option 2:
Those are your options. You do not want to use the system classpath. As soon as you have more than one Java Application (both of which need their own and sometimes conflicting libraries) the system classpath quickly becomes a liability rather than an asset.Java Code:java -cp C:/full/path/to/jdbc/driver.jar;C:/full/path/to/your/jarfile.jar full.package.path.YourMain
You know, when you get a link to a resource, don't just skim it looking explicitly for a question and answer passage that exactly matches your problem. 99% of the time, that won't exist. Simply read (and attempt to comprehend) the entire document. Those two links explained everything you needed to know, if you would have just taken the time to actually read them.
Similar Threads
-
Jdbc Driver For Oracle
By Swamipsn in forum New To JavaReplies: 0Last Post: 08-14-2007, 04:31 AM -
JDBC Driver problem
By Swamipsn in forum New To JavaReplies: 3Last Post: 08-09-2007, 03:55 PM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM -
Help with JDBC driver
By Daniel in forum JDBCReplies: 2Last Post: 07-03-2007, 08:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks