Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data in php from a java jar

Tags:

java

php

jar

I am trying to implement an application whose front end has been developed in pHp and the back end application processing is done using Java.

After the end of an event in the front end, I need to pass some values from the front end i.e. pHp to the Java jar file(This will contain the application logic) and get the results back to the pHp layer.

Before implementing it on a working model, I wanted to run it with test data to assess how it actually works but will all the reference that I had from the Internet and other books, I haven't been able to figure out why it is not working.

So, I have a testphp.jar file which has following definition :

public class main {
    main()
    {

    }
    public static void main(String args[])
    {
        if(args.length>0)
        {
            System.out.println(args[0]);
        }
        else
        {
            System.out.println("No argument");
        }
    }
}

My pHp code runs on a xampp server . I am calling the jar using the following command based on the references that I took from the internet.

exec('java -jar testphp.jar $argument', $output);

I expect the output i.e. the standard output i.e. System.out.print() to get in the $output, but I am getting an empty array every time.

I do not understand where am I going wrong.

I would be glad if some one could help me out.

like image 875
Sameer Sawla Avatar asked Apr 30 '26 00:04

Sameer Sawla


1 Answers

I'm not sure if the argument is actually replaced by the real value.

Try generating the string outside the exec. Something like:

$param = "java ....... $argument";

Note that the double quotes are relevant.

like image 190
Reinherd Avatar answered May 01 '26 14:05

Reinherd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!