Search code examples
javaphpxbee

Pass parameter to java class in PHP


How can I pass parameter to java class in PHP

<?php
$output = shell_exec('java xbee');  
print_r($output); ?>/*

above one is work fine with my java, now in my scenario, I have to pass the parameter to java class. Can anyone help me with this?


Solution

  • You can access arguments in java within your main method

    $output = shell_exec('java xbee hello'); 
    

    The hello argument would now be in args[0]

    public static void main(String[] args){
        System.out.println(args[0]);
    }
    

    That should print hello.