Ant build failed for mysql - java

When I run Ant build using mysql the following error occur
Cannot run program "mysql" (in directory
"D:\Projects\OBSWorkspace\schoolforms\db"):
CreateProcess error=2, The system cannot find the file specified
when i run mysql in local cmd the following message occur
ERROR 1045 (28000): Access denied for user 'ODBC'#'localhost' (using password:
NO)
how to run ant for generating and creating database from the script.

First of all you need to try to connect with mysql via cmd line, for example int this way mysql -u root -p root to know that you are able to do it. Secondly you can do it from ant build using this code:
<project name="mysql.test" default="mysqltest">
<target name="mysqltest">
<exec executable="cmd.exe">
<arg value="mysql" />
<arg value="-u root" />
<arg value="-p root" />
</exec>
</target>
</project>
You probably try to do it not via cmd and thats why you can't connect.

Related

CreateProcess error=2, Can not run program "python" on Ant

I have a C:\Users\Sony\Desktop\Project\Workspace\testpython\verify_fam_extended.xml:52: Execute failed: java.io.IOException: Cannot run program "python" (in directory "C:\Users\Sony\Desktop\Project\Workspace\testpython\backend\generated"): CreateProcess error=2, The system cannot find the file specified error when I run my xml code through Ant.
<exec dir="backend/generated" executable="python">
<arg line="toplevel.py"/>
<env key="PYTHONPATH" value="${dsltrans.install.path}:./backend/generated"/>
</exec>
edit python.exe must be in a directory defined in the executable path variable PATH.
Following working example assumes the presence of C:\Python33\python.exe
<project name="demo" default="main" basedir=".">
<property environment="env" />
<echo>PATH is set as: ${env.PATH}</echo>
<target name="main">
<exec dir="backend/generated" executable="python">
<arg line="--version"/>
</exec>
</target>
</project>
execute in a command session
set PATH=C:\Python33;%PATH%
ant
output
Buildfile: X:\temp\build.xml
[echo] PATH is set as: C:\Python33;...
...
main:
[exec] Python 3.3.0
edit Just checked. The executable can be executable="python" or executable="python.exe". So #cdarke is right the issue is that python.exe is not in PATH.

Ant build.xml not reading env properties

I have a cmd script file, which sets all the environment values and invoke ant class to build the java project.
I have:
<property environment="env"/>
set in build.xml and
<property name="CD" value="${env.CDTEC}"/>.
build.xml unable to read these env values set from the cmd script file. If I echo the values from command prompt that prints, but not from the ant.xml file. Getting the error as
BUILD FAILED
c:\Users\test\Projects\Spring testing\build.xml:85: c:\Users\test\Projects\Spring testing\${env.CDTEC}\lib does not exist.
I added echo message in build.xml
as
<echo message="Message from ${this.CDTEC} Client" />
and printing that as
'Message from {env.CDTEC} Client'.
Command prompt is printing these values but Ant is not able to access these env values, any idea why?
Is the environment variable set externally to ANT?
Example
Setting the variable and calling ANT
$ CDTEC=hello ant
Buildfile: /....../build.xml
build:
[echo] CDTEC=hello
build.xml
<project name="demo" default="build">
<property environment="env"/>
<target name="build">
<echo message="CDTEC=${env.CDTEC}"/>
</target>
</project>

Executing a unix command in cygwin launched from ant in eclipse

I have an ant build for a java project that I would like to trigger from within eclipse, that in turn launches a cygwin window that executes a deployment script. Is it possible to implement this without calling a new command window from ant?
Use bash.exe as the executable (replacing or parameterizing cygwin directory as needed):
<project default="default">
<target name="default">
<exec executable="c:/cygwin/bin/bash.exe">
<arg value="-c"/>
<arg value="ls c:/"/>
</exec>
</target>
</project>

Execute play from Ant script

I'm looking for a way to run play dist through an Ant build script. I've looked into using the exec task but it is not working for me. Here is what I tried:
<target name="deploy">
<exec executable="play">
<arg value="dist" />
</exec>
</target>
I'm getting this error:
C:\Users\path\to\build.xml:39: Execute failed: java.io.IOException: Cannot run program "play": CreateProcess error=2, The system cannot find the file specified
Play is already in my Path environment variable and I can execute it from the command line by typing play so that isn't the problem. I'm not allowed to use absolute paths due to sysadmin constraints.
Any ideas?
Ended up manually searching for the Play executable and storing the property to use in the exec task:
<exec executable="where" outputproperty="play.dir" osfamily="windows">
<arg value="play.bat" />
</exec>
<exec executable="which" outputproperty="play.dir" osfamily="unix">
<arg value="play" />
</exec>
<exec executable="${play.dir}" dir=" ... ">
<arg value="dist" />
</exec>

Trouble Executing Bash.exe From an Ant Buildfile in Eclipse

I've created an Ant buildfile and an associated Ant builder in my Eclipse project. The builder is executing correctly but I can't seem to pass the correct information to bash. I'm running cygwin on an XP Professional SP3 machine. I know the command works and have verified it from a cygwin terminal. I created a custom builder earlier with this command so I also know that it works from Eclipse.
Here is my build xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="BlazeLibrary.makejar" default="makejar" basedir=".">
<property name="bash" location="e:\cygwin\bin\bash.exe" />
<property name="workingdir" location="e:\cygwin\bin" />
<property name="cmdline" value="--login -c \"cd /cygdrive/c/dev/projects/droid/NDKTestApp && /cygdrive/c/dev/tools/droid/android-ndk-r4b/ndk-build"" />
<target name="nativeBuild" description="Build the native binaries using the Android NDK">
<exec dir="${workingdir}" executable="${bash}">
<arg value="${cmdline}" />
</exec>
</target>
</project>
The task runs fine but the output I indicates that the command line parameters are incorrect. Even though they are listed exactly as they should be (and verified by running from cmd prompt as well as the custom builder mentioned previously).
Here is the relevant part of the error message (the rest just vomits the help and is of no relevancy for this question):
nativeBuild:
[exec] /usr/bin/bash: --login -c "cd /cygdrive/c/dev/projects/droid/NDKTestApp && /cygdrive/c/dev/tools/droid/android-ndk-r4b/ndk-build": invalid option
[exec] Usage: /usr/bin/bash [GNU long option] [option] ... blah blah blah
I'll be the first to admit that I am an Ant noob so I'm probably missing something very obvious. I've searched but nothing really jumps out at me and the task seems to run correctly, just something funky about the command line. Thanks for any help in advance.
The immediate problem is that the ${cmdline} property is being passed to bash as a single argument - hence the very long 'invalid option'.
You could pass the command as an arg line instead:
<exec dir="${workingdir}" executable="${bash}">
<arg line="${cmdline}" />
</exec>
Or perhaps break it up into separate values. Note that you don't need the quots around the -c arg in that case:
<property name="cmdline" value="cd /cygdrive/ ..etc.. ndk-build" />
<exec dir="${workingdir}" executable="${bash}">
<arg value="--login" />
<arg value="-c" />
<arg value="${cmdline}" />
</exec>
More here.
You can still use the format in your initial post, just change your quotes around a bit, like this:
<!-- These properties hold the location of the android-ndk, for us to build our antive libs -->
<property name="bash" location="c:\cygwin\bin\bash.exe" />
<property name="workingdir" location="c:\cygwin\bin" />
<property name="cmdline" value="--login -c 'cd /path/to/project/files;/path/to/ndk_build/ndk-build;exit'" />
<target name="NDKBUILD" description="Build the native binaries using the Android NDK">
<exec dir="${workingdir}" executable="${bash}">
<arg line="${cmdline}" />
</exec>
</target>
Note the usage of " " to denote the XML string, but ' ' to denote command lines passed to cygwin/bash.
Also, when using this script in my android builder (heavily customised ant script with extensive source preprocessing) I ran into issues where the ant build was "Already In Progress".
To this end, I added an exit command to the end of the bash script, so the cygin bash process is always closed after being called.

Categories

Resources