Wednesday, August 22, 2012

Linux: Cannot Execute Binary File

There are many cases where we need to execute a java command providing specific jars to the class path, but there are some specific differences while providing jars on the class path in linux and windows env.

Consider a scenario where we need to encrypt a password in JBoss As.We use

java -cp client/jboss-logging-spi.jar;common/lib/jbosssx.jar jagadesh

Encoded password: 7b228572f1d62ebcdf8592078de921bc

The above command is executed on a windows env, which is successful. But when we run the same command on linux systems it fails giving ,

-bash: /software/jboss/as/5.0/common/lib/jbosssx.jar: cannot execute binary file

It is unable to execute the binary file.

Solution: the reason for this is, when we provide the class path, we provide them by using a separator ‘;’ on windows env. But the same ‘;’ is used a statement separator in bash shell (or other shells).We cannot use the same ‘;’ separator for the java command in both the env.In order to execute the same command in linux, we need to provide a different separator which linux can understand. We use ‘:’

We can execute now as,

java -cp client/jboss-logging-spi.jar:common/lib/jbosssx.jar jagadesh
Encoded password: 7b228572f1d62ebcdf8592078de921bc

Happy learning , More To Come