php exec java错误java未找到

Everybody who can use a command php exec to run a java. I have a problem on my coding to testing java.

$output = exec("java -version 2>&1");
echo $output;

When I run a script on web browser I found,

java: not found

How can I work with php exec java. P.S. I could run a command php java -version on a shell command.

Thanks in advance.

As the error is saying, java is probably not installed on your system. You didn't specify an operating system but here is the output of java -version in ubuntu without java:

x@y:~$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Try: sudo apt-get install <selected package>

As you can see it even tells you how to install java, the package I would suppose you need is default-jre so you can go ahead and run sudo apt-get install default-jre.

As to being able to run php java -version that means you have a file named java in the current working directory which runs php (for some reason?).

Of course you will have to research how to install java on your type of operating system, google is your friend here.