aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Execute ant build file from a java source Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Execute ant build file from a java source" Watch "Execute ant build file from a java source" New topic
Author

Execute ant build file from a java source

Tiju Thomas
Greenhorn

Joined: May 25, 2008
Posts: 22
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
Marshal

Joined: Mar 22, 2005
Posts: 42641
    
  65
This should help: http://www.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html


Ping & DNS - my free Android networking tools app
Tiju Thomas
Greenhorn

Joined: May 25, 2008
Posts: 22
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
Marshal

Joined: Mar 22, 2005
Posts: 42641
    
  65
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

Joined: Jun 25, 2001
Posts: 16250
    
  21

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



Customer surveys are for companies who didn't pay proper attention to begin with.
Tiju Thomas
Greenhorn

Joined: May 25, 2008
Posts: 22
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

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

Joined: May 25, 2008
Posts: 22
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 !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execute ant build file from a java source