Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set environment from ant build file

 
Priyanka Chaurishia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Priyanka Chaurishia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic