Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » MySQL JDBC Driver Not Found From build.xml
MySQL JDBC Driver Not Found From build.xml [message #1417187] Thu, 04 September 2014 22:13 Go to next message
Garry Claridge is currently offline Garry ClaridgeFriend
Messages: 3
Registered: September 2014
Junior Member
I have exported the Java code from an Altova MapForce data mapping project. It maps from QuickBooks to MySQL.

Eclipse is being used to compile the project code. However, I am receiving the error:
[java] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

The driver jar has been added to the Build Path via the Referenced Libraries. I can compile other test classes using the driver. However, it is only when compiling from the build.xml that I receive the error.

Here is the build.xml
--------------------------------------------------------------
<?xml version="1.0"?>
<project name="Mapping" default="test" basedir=".">
<property name="build.sysclasspath" value="last"/>
<target name="compile">
<javac srcdir="." classpath="." />
</target>
<target name="test" depends="compile">
<java classpath="C:\Users\GarryClaridge\Documents\MapForceJava\Test4" classname="com.mapforce.MappingConsole" fork="true" failonerror="true">
<arg line="${cmdline}"/>
</java>
</target>
<target name="clean">
<delete>
<fileset dir=".">
<include name="**/*.class"/>
<include name="*.jar"/>
</fileset>
</delete>
</target>
<target name="manifest" depends="compile">
<mkdir dir="C:\Users\GarryClaridge\Documents\MapForceJava\Test4/META-INF"/>
<manifest file="C:\Users\GarryClaridge\Documents\MapForceJava\Test4/META-INF/MANIFEST.MF" mode="replace">
<attribute name="Created-By" value="MapForce 2014r2sp1"/>
<attribute name="Main-Class" value="com.mapforce.MappingConsole"/>
</manifest>
</target>
<target name="jar" depends="manifest">
<jar destfile="Mapping.jar" manifest="C:\Users\GarryClaridge\Documents\MapForceJava\Test4/META-INF/MANIFEST.MF" basedir="." includes="**/*.xml **/*.class **/*.png **/*.wsdl **/MANIFEST.MF" excludes="**/*.java"/>
</target>
</project>
------------------------------------------------------------

Here is the path to the driver (from the Eclipse project Build Path):
C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.32-bin.jar


Any help or thoughts will be appreciated.

Thank you.

Garry
Re: MySQL JDBC Driver Not Found From build.xml [message #1417190 is a reply to message #1417187] Thu, 04 September 2014 22:21 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3510
Registered: July 2009
Senior Member

This is more of an Ant question than an Eclipse question, especially since that's a runtime exception rather than a compile-time issue. The "java" task you're invoking in your "test" target doesn't list the connector jar in its classpath attribute.

Nitin Dahyabhai
Eclipse Web Tools Platform
Re: MySQL JDBC Driver Not Found From build.xml [message #1417196 is a reply to message #1417190] Thu, 04 September 2014 22:40 Go to previous messageGo to next message
Garry Claridge is currently offline Garry ClaridgeFriend
Messages: 3
Registered: September 2014
Junior Member
Thanks Nitin - will check it out.

All the best.

Garry

[Updated on: Thu, 04 September 2014 22:41]

Report message to a moderator

Re: MySQL JDBC Driver Not Found From build.xml [message #1417269 is a reply to message #1417187] Fri, 05 September 2014 03:58 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 09/04/2014 04:15 PM, Garry Claridge wrote:
> I have exported the Java code from an Altova MapForce data mapping
> project. It maps from QuickBooks to MySQL.
>
> Eclipse is being used to compile the project code. However, I am
> receiving the error:
> [java] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
>
> [snip]

Uh, there's a lot to say here.

1. Never draw a JAR in from outside your project. This creates an
unportable .classpath file in the project and you can't share your
project with anyone else including yourself if you work on other
computers. Put the driver into <project>/lib or somewhere like that
inside the project.

1bis. Use Maven, but that's a different, advanced discussion.

2. The javac task says all your source code starts in the project root
(which isn't true) and all the libraries (JARs) are there too. Instead I
would expect something like this:

<property name="src.dir" location="${basedir}/src" />
<property name="lib.dir" location="${basedir}/lib" />
<property name="build.dir" location="${basedir}/build" />
<property name="classes.dir" location="${build.dir}/classes" />

<path id="classpath">
<fileset dir="${lib.dir}">
<include name="*/*.jar" />
</fileset>
</path>

<javac srcdir="${src.dir}"
destdir="${classes.dir}"
classpathref="classpath"
includeantruntime="false" />


I hope this helps; it's late and I have to go. Play with it and come
back asking more.

Russ
Re: MySQL JDBC Driver Not Found From build.xml [message #1417271 is a reply to message #1417269] Fri, 05 September 2014 04:01 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 09/04/2014 09:58 PM, Russell Bateman wrote:
> Uh, there's a lot to say here.
>
> [snip]

Sorry, yeah, Nitin is right, this really isn't for this forum. Hope I
helped a bit anyway.
Re: MySQL JDBC Driver Not Found From build.xml [message #1417278 is a reply to message #1417271] Fri, 05 September 2014 04:27 Go to previous message
Garry Claridge is currently offline Garry ClaridgeFriend
Messages: 3
Registered: September 2014
Junior Member
Thanks Russell,

I was able to solve the run, within Eclipse, problem by adding the path to the driver jar within the build.xml

------------------------------------------------------------
<project name="Mapping" default="test" basedir=".">
<property name="build.sysclasspath" value="last"/>
<target name="compile">
<javac srcdir="." classpath="." />
</target>
<target name="test" depends="compile">
<java classpath="C:\Users\GarryClaridge\Documents\MapForceJava\Test4;C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.32-bin.jar" classname="com.mapforce.MappingConsole" fork="true" failonerror="false">
<arg line="${cmdline}"/>
</java>
</target>
...

----------------------------------------------------------------------

However, it is temporary and is a lesson in project management Smile

All the best.

Garry
Previous Topic:Error with Eclipse Hadoop plugin
Next Topic:Error Trying to Run JUnit Tests
Goto Forum:
  


Current Time: Wed Oct 16 11:44:57 GMT 2019

Powered by FUDForum. Page generated in 0.03717 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top