问题
I want to run an SQL query using the ant tasks, and I am using the SQLServerDriver (sqljdbc.jar). This jar file is located where I have all of my jars needed to run the application
(WebContent/WEB-INF/lib)
This directory is my classpath which I defined it in another TASK Command:
<!-- Define el classpath que es utilizado para compilar los archivos -->
<path id="classpath">
<fileset dir="${libs.dir}">
<include name="*.jar" />
</fileset>
</path>
This jar file is also indicated in my ecplise external jar files. The ant command that I am trying to run is the following:
<target name="db.query" description="Ejecuta un query de SQL">
<sql driver="${db.driverT}" url="${db.urlT}" userid="${db.userT}"
password="${db.passwordT}" print="TRUE">
SELECT * FROM T007_EDO;
</sql>
</target>
What should I do to correct my error?
回答1:
The answer to this question was to simply add the line to my db.query task.
classpathref="classpath"
So I have my classpath deffinition of the place where the jar file is located in:
<path id="classpath">
<fileset dir="${libs.dir}">
<include name="*.jar" />
</fileset>
And I reference that in my ant task:
<target name="db.query" description="Ejecuta un query de SQL">
<sql driver="${db.driverT}" url="${db.urlT}" userid="${db.userT}"
password="${db.passwordT}" print="TRUE" classpathref="classpath">
SELECT * FROM T007_EDO;
</sql>
来源:https://stackoverflow.com/questions/8734679/sql-ant-task-error-class-not-found-jdbc-driver-com-microsoft-sqlserver-jdbc-sq