• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

MySQL with ant: can not find driver class

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am testing a MySQL jdbc program. My project looks like this:

--build
-- mysql-jdbc-connector.jar
--classes
-- ddd.class

so I use
-----------------
<jar dest="dd.jar">
<fileset dir="${classes}"/>
<fileset dir="{build}"/> <!-- add MySQL-jdbc-con.jar into it -->
</jar>

<java classname="ddd" classpath="dd.jar" />
-------------

But still have the error, "can not find class com.mysql.jdbc.Driver". I unzip the dd.jar, I do see the MySql driver inside.

I don't know why. Could you help me?

after this
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be clear, are you placing a JAR inside of a JAR?
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Dirk,

no, I just want to make a single executable jar file.

Actually I solve the part of problem. I add the classpath "ant.java.classpath" to "java" target. It works.

But the problem is, when I go to windows console, to java -jar myjar.jar. It NOT works, still can not find "com.mysql.jdbc.Driver". Actually the mysql driver jar is located in ./jar folder.

How to work out?

Thanks
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand correctly, you need to add the JAR file to your CLASSPATH.
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Dirk,

Below is what I have tried to do. I have to place the MySQL driver jar into my jar file. My goal is to make the jar file self-executalbe, say,double click to lanuch it.

Error should be here
<attribute name="Main-Class" value="classes/${project-main-class}"/>
<attribute name="Class-Path" value="lib/mysql-connector***-bin.jar"/>

Thanks.

Edward


 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That NoClassDefFoundError is due to
<attribute name="Main-Class" value="classes/${project-main-class}"/>
which should be
<attribute name="Main-Class" value="${project-main-class}"/>
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
That NoClassDefFoundError is due to
<attribute name="Main-Class" value="classes/${project-main-class}"/>
which should be
<attribute name="Main-Class" value="${project-main-class}"/>



HI, Lasse, thanks for your response. But it still doesn't work.

The main class , ddd.java , doesn't belong to any package. It is plain. Its class file, ddd.class, just is placed into classes directory.

The question is, I should tell the compiler: "classes\ddd" or just "ddd" ? I guess should be the former one.

But it doesn't work.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you've a class that is not part of a package, you can add it to your CLASSPATH by specifying the location of the directory where the class resides.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set class path in build.xml of ANT




reply
    Bookmark Topic Watch Topic
  • New Topic