aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to set environment from ant build file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to set environment from ant build file" Watch "How to set environment from ant build file" New topic
Author

How to set environment from ant build file

Priyanka Chaurishia
Greenhorn

Joined: Oct 12, 2011
Posts: 9


Hello ,
Here is what the current process. In the command line I run a setenv.cmd which sets up required classpath. Than I run normal targets .
Now I want to run the same build file from eclipse. But since I am not invoking batch file before ant build targets it is not able to find some custom task files.
There are lot of jars and environment variable in batch file so adding each and everyone in classpath element is not possible.
I added something like following :
<target name="pc">
<exec dir="${basedir}" executable="cmd" > <arg line="/c setenv.cmd"/> </exec>
</target>
But task def are before it . And they are giving error that ABCClass cannot be found.
<taskdef name="xmltask" classname="com.abc.xyz.ABCClass"/>

Please suggest.
Thanks
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 971
    
  10

Even if the ordering here was correct I'm not convinced that you have the right approach. The newer Ant versions (I can't remember at which version it was introduced) automatically include the jar files in directory %HOME%\.ant\lib and these can be used to find the classes needed for loading <anttask> definitions.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

Your Ant script depends on CLASSPATH being set? Seems like the wrong approach to me. Instead, I would set a classpath variable in the Ant script using JAR file locations provided in a properties file. That way the Ant script will work from either the command line or from Eclipse.

By the way, if you started Eclipse from the command line after running setenv.bat, I suspect that the Ant script would run even from within Eclipse...


JBoss In Action
Priyanka Chaurishia
Greenhorn

Joined: Oct 12, 2011
Posts: 9
Thanks for input guys.

Just to give some more background. The project I am dealing with is an old project though still in production . Since I am thrown to look into that I tried to build it from eclipse and there I am trapped since I am not able to run the setenv.cmd . I am not aware of entire build process but the same targets work with command line if I invoke setenv.cmd prior calling to build targets.

I tried the approach Peter suggested , but still it gives error .This time not for being class not found but for some property set by setenv.cmd.

Current build process is not intuitive to me as well. But I need to find a way to build it from editor.

Thanks
Priyanka
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

Then do what I do. Use Eclipse as an Editor. And when it comes time to build the project, go to a command line and do it there.
 
Don't get me started about those stupid light bulbs.
 
subject: How to set environment from ant build file
 
Similar Threads
Problem running .bat script within ant in Eclipse
Running WebLogic sh script that sets environment variables from ANT
Running .cmd file using "ant"
Getting error while making java proxy using clientgen
run two <exec> task in the same command shell