1

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:

  1. Added /usr/local/mysql/bin to my path and verified with "echo $PATH".
  2. Added /usr/local/mysql/bin to my classpath in Eclipse through "properties" on the project.
  3. 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 executable="mysql" input="insertdb.sql">
            <arg line="${mysql.params}" />
        </exec>
    </target>
</project>

3 Answers3

2

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

Community
  • 1
  • 1
KevinS
  • 7,715
  • 4
  • 38
  • 56
0

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.

ig0774
  • 39,669
  • 3
  • 55
  • 57
  • Thanks ig0774. No reason other than I just don't know any better at this point! :) I've add the path to the build.xml file properties and to the Ant runtime class path in the Eclipse preferences, but still get the same message. I must be missing the correct place to add it, but I don't see any other places. – CatCollector Sep 05 '11 at 04:23
0

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>
KevinS
  • 7,715
  • 4
  • 38
  • 56
  • Same error with both methods. Really strange. Not that big of a deal, I guess. It's in an exercise in a book I'm working through to learn this. If I use the full path to mysql, it works fine. I would just like to know why because I'm sure it will come up again in the real world. :) Thanks for your help! – CatCollector Sep 07 '11 at 03:20