I'm learning Java and Eclipse on a Mac. I have an Ant build file in a project that contains sql statements to create a MySql database and tables and insert rows to set up data for the project. I have MySql set up correctly and can use the "mysql" command in terminal with no problem, but when I run the Ant build.xml file in Eclipse, I get: "BUILD FAILED. Cannot run program "mysql": error=2, No such file or directory" I have done the following without success:
- Added /usr/local/mysql/bin to my path and verified with "echo $PATH".
- Added /usr/local/mysql/bin to my classpath in Eclipse through "properties" on the project.
- Added build.xml to the build path in Eclipse (just for grins.)
I am running:
- Mac OS X 10.7.1
- Eclipse Indigo Build id: 20110615-0604
- MySql 5.5.15-osx10.6-x86_64
Thanks for your help!
Here is my build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="publisher" default="all" basedir=".">
<property name="mysql.params" value="-u publisher -ppublisher -D publisher" />
<target name="all" depends="cleandb, createdb, insertdb"></target>
<target name="cleandb">
<exec executable="mysql" input="cleandb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
<target name="createdb">
<exec executable="mysql" input="createdb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
<target name="insertdb">
<exec exe开发者_运维问答cutable="mysql" input="insertdb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
</project>
Does it work when you run the Ant build from the command line? If so, its probably the same problem described here:
Running ant through eclipse it doesn't find environment variables, but running ant through terminal is fine
Any reason not to just be using Ant's SQL task and Connector/J?
In any case, it sounds like you just haven't made sure that that /usr/local/mysql/bin
is available on the PATH
used when executing the Ant build. There's an Environment tab in the Ant build configuration that should allow you to modify the path for the environment Eclipse will run your Ant build file in.
There's a couple of things I would try:
Set the searchpath attribute to true (it is false by default):
<target name="cleandb">
<exec executable="mysql" input="cleandb.sql" searchpath="true">
<arg line="${mysql.params}" />
</exec>
</target>
Use a nested env element to set the path.
<property environment="env"/>
<exec ... >
<env key="PATH" path="${env.PATH}"/>
</exec>
精彩评论