• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute ant build file from a java source

 
Tiju Thomas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

I wanted to execute an ant build file from java code using the org.apache.tools.ant.Project APIs.. Even though I was able to run the ant script successfully through the ant perspective of the IDE, I am getting error calling the script from java.. Not much information is available in using Project project = new Project(); project.init();..

Could anyone help me find more information in calling an ant build file from java code?

Thanks,
Thomas
 
Ulf Dittmer
Rancher
Posts: 42968
73
 
Tiju Thomas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much Ulf. This defenitely helped.

But I do not know why I am getting a

BUILD FAILED
D:\Workspaces\SSDownload\SS Download\src\ddlutils-ant-build.xml:27: Could not parse or write data file D:\Workspaces\SSDownload\SS Download\src\db-data.xml

due to

org.apache.ddlutils.DdlUtilsException: java.net.MalformedURLException: unknown protocol: d
at org.apache.ddlutils.io.DatabaseDataIO.writeDataToDatabase(DatabaseDataIO.java:730)

This error I do not get running the build file directly!!! I am trying to migrate a database using the DDLUtils API inside the ant build file. Any tips?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like the path you're providing ("D:\...") can't be processed; at least that's what I think the "unknown protocol: d" might mean. Try prefixing it by "file:///" so that it becomes an actual URL (instead of a file name).
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the key is that it's a MalformedURLException. Meaning that they support getting the data from not only files, but via any other supported protocol (such as http or ftp).

It's [/i]possible[/i] that the normalized filename syntax might have worked:

D:/Workspaces/SSDownload/SS Download/src/db-data.xml

Assuming that capitalization is accurate and that whatever mechanism is feeding the filename is handling the space in the path correctly. However to be totally safe, try this:

file:///D:/Workspaces/SSDownload/SS Download/src/db-data.xml

This might work:

file:///D:/Workspaces/SSDownload/SS%20Download/src/db-data.xml


 
Tiju Thomas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the info..I have not got any urls specifically like D:\

Might be I have to give my database url or the outputFile diffrently?

Here is my build file..




But one thing I cant figure out is why this builds fine when I run it through the ant console manually and not this way.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to take a look at how the writeDataToFile target operates, what's the pass directory it uses? That's where the D:\ will be coming from.
 
Tim Holloway
Saloon Keeper
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:You need to take a look at how the writeDataToFile target operates, what's the pass directory it uses? That's where the D:\ will be coming from.


Definitely. Are the db-schema and db-data files on the D: drive?

It's possible that this particular task wasn't designed Windows-friendly.
 
Tiju Thomas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly Tim. Both the files are on the D drive. But I am able to read the db-schema but not the db-data alone.

database-write:
Jan 13, 2010 11:41:08 AM org.apache.ddlutils.task.DdlToDatabaseTask readSingleSchemaFile
INFO: Read schema file D:\Workspaces\SLDownload\SS Download\src\db-schema.xml
.
.
.
INFO: Executed 81 SQL command(s) with 0 error(s)
Jan 13, 2010 12:01:07 PM org.apache.ddlutils.task.WriteSchemaToDatabaseCommand execute
INFO: Written schema to database

BUILD FAILED
D:\Workspaces\SLDownload\SL Download\src\ddlutils-ant-build.xml:27: Could not parse or write data file D:\Workspaces\SLDownload\SL Download\src\db-data.xml

I tried deleting the contents of the db-data.xml and then running the script, but still !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic