Passing Value From Php To Java Application

Hello everyone,

I am bothering again with a weird question again. Earlier I tried to verify digital signature of pdf/doc file. As I saw, it is wise to do it with java application, i made a jar file for this purpose. Now what i need to do, call the jar file with a input (path of the file) and get the output. I could not take input but I could get output. The code is like:

$ac = Yii::app()->basePath;

exec(‘java -jar ‘.$ac.’\\…\\jar\\VerifyPdf6.jar’, $output);

echo "<pre>";

print_r($output);

echo "<pre>";

echo "</br>";

Now,this works and I get the output from $output. Now I want to take an input and pass the value in the jar ‘VerifyPdf.jar’. that value will be used in the file parameter. Now, many people suggested to pass a value along with execution (exec) and get the value in java using request.getParameter(). But, in java application, the function was not recognized and i think it is mainly used in java servlet and jsp but I am not so sure. Can anyone help me with this ?

The code I am working to test now is :

$arg1 = "This is test from the php";

exec(‘java -jar Testphp2java.jar arg1’, $output);

echo "<pre>";

print_r($output);

echo "</pre>";

here, I want to take the $arg1 and print it from java ($output)…

Thank you very much for reading this. Any feedback will be big help for this newbie.

Does the class that is executed with the jar command expect arguments?

http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html

I got the answer:

PHP PAGE:

<?php

$some_value = ‘D:\NetBeansProjects\Testphp2java\dist’;

//exec(‘java -jar Testphp2java.jar this_is_the_valye’, $output);

exec("java -jar Testphp2java.jar $some_value", $output);

echo "<pre>";

print_r($output);

echo "</pre>";

?>

JAVA APPLICATION:

/**@author Saqib */

public class Testphp2java

{

public String a = &quot;Testing from string a&quot;;





public Testphp2java() throws Exception


{


    System.out.println(&quot;Hello, This is testing...1,2,3...Done&quot;);


    System.out.println(&quot;String a: &quot; + a);     


    


}





public static void main(String[] args) 


{


    try


    {


        String abc = args[0];


        System.out.println(args[0]);


        System.out.println(abc);


        new Testphp2java();


    }


    catch(Exception e)


    {


        System.out.println(e);


    }


}

}