After writing article How to Upgrade OPatch to Latest Version, a few reader raised concerns that they got following error when calling opatch binaries.
./opatch: line 839: [: too many arguments Java (1.7) could not be located. OPatch cannot proceed! OPatch returns with error code = 1
Even after ensuring that java is installed and all relevant environment variables were also set correctly. The OPatch utility’s md5sum was compared and there was no corruption.
To fix this we can use the “-jdk” argument of opatch to explicitly specify the java home by using following command:
$ORACLE_HOME/OPatch/opatch version -jdk $ORACLE_HOME/jdk
And then subsequent calls to opatch should work if not then you can use this “-jdk $ORACLE_HOME/jdk” clause everytime when you call opatch.
This issue was faced by a few readers, though they confirmed that the env. variables were set appropriately but its very unlikely that this error could occur without any gaps with env. variables and that’s why explicitly specifying the java home does work. Still in case you can’t figure out the gap with env. variable you could always use this workaround.
Feel free to comment below if you faced this error but the issue is not resolved even after using -jdk clause and we’ll work of identifying the root cause together.