0

I have a PHP Project with the name itext. Inside this folder I have a workspace folder. So the Path to the Java Class file is like this:

itext/workspace/sampleproject/checkFonts.java

I have an index.php file in itext folder. How can I execute the shell_exec command in the index.php for the java file located in the above path?

UPDATE:

As per the answer I tried out stuffs and executed the below code and it works but I am getting the below error:

$output = array();
exec('java workspace/itext/src/itext/CheckFonts 2>&1',$output);
print_r($output);

Error:

Array ( [0] => Error: Could not find or load main class workspace.itext.src.itext.CheckFonts )

2
  • This may be helpful stackoverflow.com/a/3023715/1793718 Commented Aug 18, 2015 at 7:43
  • Your error is related to the original question as is more a matter of your coding error. You should open a new question if you have a problem with your code. Commented Aug 19, 2015 at 14:30

1 Answer 1

1

You can specify any path relative to the file your code is running from. So from your index.php the path would be workspace/sampleproject

If you want to use the full explicit directory you can use realpath() function:

realpath('workspace/sampleproject');

Here's a guide to running Java at the command line for windows environment: http://www.skylit.com/javamethods/faqs/javaindos.html

Your example code might be:

$javaPath = realpath('workspace/sampleproject');
$output = shell_exec('C:\ProgramData\Oracle\Java\javapath\java.exe '
                     . $javaPath . DIRECTORY_SEPARATOR . 'checkFonts');`
Sign up to request clarification or add additional context in comments.

14 Comments

How does that help me in running a java class from shell_exec command?!!
exec [path to java executable/]java [path to java file]checkFonts - where [] marks optional?
I have a problem. I changed the question.check it
I want to know how its run that is first it should be getting compliled and then executed
I edited my answer with link showing how to complile and run. Does that answer your Q?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.