ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <>
Subject Re: Question on finding what executable ant uses to javac/jar
Date Wed, 28 Jun 2006 11:11:21 GMT
Ben Stringer wrote:
> On Tue, 2006-06-27 at 21:56 -0700, Michael Wenk wrote:
>>I am a fairly new to ant, and unfortunately, I have not been able to find my 
>>answer by googling and searching the list archives, tho I have to figure its 
>>been asked before. I need help in calling an external program.  This program 
>>has been compiled with make.  There's some internal versioning information 
>>that needs to be inserted into a file in the end result jar file.  I do this 
>>by calling a script.  I figured out how to use <exec> to call my script:
>><exec dir="${src}" executable="../../tools/" output="version.tmp">
>>    <arg line="${ant.javac} ${ant.jar}"/>
>>What I cant figure out is how to get ant to actually pass the full path to 
>>javac and the full path to jar which it has used and will use.  The above 
>>doesn't work, nor does any parameter I give in the line work(It is like it 
>>doesn't substitute the variables.)  I can workaround this, but I would 
>>prefer the clean solution.  Ive checked the FAQ, manual, wiki, etc.  Much of 
>>that problem is unfortunately placing jar or javac in a query is pointless, 
>>and I cannot formulate my search such that it doesn't have this.
>>Anyone know how to get ant to spill what javac and what jar program it uses?
> Hi Mike,
> try running ant with the -diagnostics option set. This will show a
> number of properties being set to allow ant to locate resources. Ant
> uses the JAVA_HOME environment variable to find javac, and you should be
> able to access this as a property within ant using ${java.home}.

 > I could not find a way to get any to print out the path to javac, but I
 > would think that ${java.home}/bin/javac would be a safe assumption in
 > most cases.


     public static String getJdkExecutable(String command) {
         if (IS_NETWARE) {
             // Extrapolating from:
             // "NetWare may have a "java" in that directory, but 99% of
             // the time, you don't want to execute it" -- Jeff Tulley
             // <>
             return command;

         File jExecutable = null;

         if (IS_AIX) {
             // On IBM's JDK 1.2 the directory layout is different, 1.3 
             // Sun's layout.
             jExecutable = findInDir(JAVA_HOME + "/../sh", command);

         if (jExecutable == null) {
             jExecutable = findInDir(JAVA_HOME + "/../bin", command);

         if (jExecutable != null) {
             return jExecutable.getAbsolutePath();
         } else {
             // fall back to JRE bin directory, also catches JDK 1.0 and 1.1
             // where java.home points to the root of the JDK and Mac OS 
X where
             // the whole directory layout is different from Sun's
             return getJreExecutable(command);

That is, its usually in JDK_HOME/bin except when it isnt.

I'm not sure if ant uses the jar command from
> ${java.home}/bin, or it's own implementation - I'm sure someone else can
> answer this.

custom classes in ant.jar. Feel free to reuse under the apache license.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message