java - calling methods in a jar file from php -


i running jar file php function.

exec("java -jar hel.jar", $outputarray); 

but want call particular method in jar file , send parameters methods , final output.

example:-

public class hel {      public static void main(string[] args) {          hel he=new hel();         he.getname("john");     }     public string getname(string name){         system.out.println(name);         return name;      }  } 

i want send string value parameter method "getname" , final output. suggestions?

you can call main method main class. java manual:

-jar filename

executes program encapsulated in jar file. filename argument name of jar file manifest contains line in form main-class:classname defines class public static void main(string[] args) method serves application's starting point.

so work have setup manifest in jar , write main class call function want. when that's done, append arguments exec call , should work.

you have create manifest file "manifest.mf" in "meta-inf" folder of jar these contents:

manifest-version: 1.0

main-class: this.is.your.package.hel

and can add arguments exec this:

exec("java -jar hel.jar first_argument second_argument", $outputarray); 

add quotes if arguments need spaces. arguments show in string[] args array.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -