Site icon NgDeveloper

Executing jar inside php step by step explained

Java Program:

[java]
package in.javadomain;

public class Hello {

public static void main(String[] args) {
Hello h = new Hello();
System.out.println(h.helloName("Javadomain.in"));
}

private static String helloName(String name){
return "Hello "+name;
}

}
[/java]

Output:

[plain]
Hello Javadomain.in
[/plain]

 

Now Create the Jar like below using Eclipse,
Rightclick on the project in eclipse -> Export -> Runnable JAR file -> Choose the Project and Export location.

Note: Do not forgot to choose the package required libraries into generated JAR under library handling.

Now Run the Above Created Jar in PHP:

[php]
<!–?php echo exec("java -jar hello.jar "); ?–>
[/php]

Output:

[plain]Hello Javadomain.in[/plain]

 

Recommended Java Books:

Recommended PHP Books:

Exit mobile version