Reputation: 9201
I am getting the following error message when I try to run the following build.xml file to work with mysql from my java application in eclipse:
BUILD FAILED
d:\mypath\workspace\appname\database\build.xml:14: Execute failed: java.io.IOException: Cannot run program "mysql": CreateProcess error=2, The system cannot find the file specified
Here is the code for 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>
From eclipse, I am running the file as "Ant Build..." and am calling createdb.sql first. Thus, the line that is throwing is the first line that is being asked to execute, which is:
The problem seems to be that the script is not able to locate mysql. From the windows command line, I am able to call the instance of the database using the following path:
d:\mypath\MySQL\MySQL Server\bin\mysqld
I think the xml file needs to specify the path of the mysql installation, but I am not sure how to do that while also passing the parameters required in the code above. This is my first time working with Ant and with mysql, so the syntax is new to me.
Can anyone show me how to fix the code above so that it can find my database?
EDIT:
I followed whiskeyspider's suggestion and edited my code to become the following:
-- I had a bunch of code here that I am now omitting for brevity because
-- there is a newer, revised version of the code in the second edit below.
It may help some readers to know that I am trying to use code from this tutorial. The difference is that I am using version 5.6 of mysql and Version: Juno Service Release 1 Build id: 20120920-0800 of Eclipse. The tutorial uses older versions of both applications, which is what is causing the confusion.
SECOND EDIT:
I changed the build.xml file again to implement whiskeyspider's second round of corrections. The script now accesses the mysql database, but there is another message about which I have a question, below.
Here is the new build.xml code, which runs correctly now:
<?xml version="1.0" encoding="UTF-8"?>
<project name="publisher" default="all" basedir=".">
<property name="mysql.params" value="-u publisher -ppublisher -D publisher" />
<property name="mysql.exec.path" value="d:\\mypath\\MySQL\\bin\\"/>
<target name="all" depends="cleandb, createdb, insertdb"></target>
<target name="cleandb">
<exec executable="${mysql.exec.path}/mysqld" input="cleandb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
<target name="createdb">
<exec executable="${mysql.exec.path}/mysqld" input="createdb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
<target name="insertdb">
<exec executable="${mysql.exec.path}/mysqld" input="insertdb.sql">
<arg line="${mysql.params}" />
</exec>
</target>
</project>
Here is the log reported in the eclipse console when build.xml is run:
Buildfile: d:\mypath\workspace\publisher\database\build.xml
createdb:
[exec] Warning: Using a password on the command line interface can be insecure.
insertdb:
[exec] Warning: Using a password on the command line interface can be insecure.
BUILD SUCCESSFUL
Total time: 1 second
Can anyone tell me how I can address this warning by improving security when I need to use passwords to get into databases from ant code run using eclipse? How, specifically, can I change my code so that the same tasks are performed without the security risk?
Upvotes: 2
Views: 6682
Reputation: 12332
Create a property with the path to the executable:
<property name="mysql.exec.path" value="C:/path/to/it" />
You can make it portable by first loading a local properties file that may override it, for example:
<property file="${user.home}/local.properties" /> // can override mysql.exec.path property, if necessary
<property name="mysql.exec.path" value="C:/path/to/it" /> // if not, use the default
Then reference it like so:
<exec executable="${mysql.exec.path}/mysql" input="cleandb.sql">
<arg line="${mysql.params}" />
</exec>
Upvotes: 1
Reputation: 33451
The best way to achieve your goal is to add .../mysql/bin
folder to your PATH
.
If it's not an option, you can specify mysql location via property: -Dmysql.bin.dir=/path/to/mysql
and then use <exec executable="${mysql.bin.dir}/mysql" input="cleandb.sql">
Upvotes: 2