1
votes

I'm using Fedora 18 and JDK 1.7.13 installed in /usr/java. All executable files under bin folder have -rwxr-xr-x permission. I set both ANT_HOME and JAVA_HOME in my ~/.bashrc as:

export ANT_HOME=/home/m/application/apache-ant-1.8.2
export JAVA_HOME=/usr/java/jdk1.7.0_13/

and I have a build.xml file which says:

<exec dir="${java.home}/bin/" executable="keytool"/>

but after running ant I got this exception:

/home/m/workspace/build.xml:58: Execute failed: java.io.IOException: Cannot run program "keytool" (in directory "/usr/java/jdk1.7.0_13/jre/bin"): error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) at java.lang.Runtime.exec(Runtime.java:615) at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:827) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:445) . . .

at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Any idea?

2
Well the directory you're xml file is opening is /usr/java/jdk1.7.0_13/bin/ but it looks like ant is looking in /usr/java/jdk1.7.0_13/jre/bin - Saggio
Run Ant in verbose mode ant -v ... and check ls -al /usr/java/jdk1.7.0_13/jre/bin to make sure things are really there. - carlspring
Did you check, does the file /usr/java/jdk1.7.0_13/jre/bin/keytool exist? - Andy
@Saggio: Well, you have keytool in both the JDK's and JRE's bin directories either way. Must be something else. - carlspring
@carlspring I can run /usr/java/jdk1.7.0_13/jre/bin/keytool from bash - m Lotfizad

2 Answers

3
votes

Try:

  • export ANT_HOME=/path/to/ant

  • export PATH=$ANT_HOME/bin:$PATH

  • <exec executable="keytool"/>

or:

<exec executable="${java.home}/bin/keytool"/>

As the dir attribute tells Ant in which directory to execute the binary, not what the path to it is.

1
votes

It seems when JAVA_HOME is set in my ~/.bashrc it works, otherwise it doesn't!

Also when searching my system for alternative I found that the keytool command is not even in my slaves!

Here is my log from running alternatives --display java:

java - status is manual.
 link currently points to /usr/java/latest/jre/bin/java
/usr/lib/jvm/jre-1.7.0-openjdk/bin/java - priority 170009
 slave keytool: /usr/lib/jvm/jre-1.7.0-openjdk/bin/keytool
 slave orbd: /usr/lib/jvm/jre-1.7.0-openjdk/bin/orbd
 slave pack200: /usr/lib/jvm/jre-1.7.0-openjdk/bin/pack200
 ...
 slave jre_exports: /usr/lib/jvm-exports/jre-1.7.0-openjdk
 slave jre: /usr/lib/jvm/jre-1.7.0-openjdk
 slave java.1.gz: /usr/share/man/man1/java-java-1.7.0-openjdk.1.gz
 slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.7.0-openjdk.1.gz
 ...
/usr/java/latest/jre/bin/java - priority 20000
 slave keytool: (null)
 slave orbd: (null)
 slave pack200: (null)
 ...
Current `best' version is /usr/lib/jvm/jre-1.7.0-openjdk/bin/java.

so I asked my root to remove jdk from alternatives till I can address it directly by $JAVA_HOME whenever it's needed. Fortunately, problem solved.