简体   繁体   中英

error=2, No such file or directory at java.lang.ProcessBuilder.start

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM