I tried JAVA bridge to get output from my jar file followed this https://stackoverflow.com/a/10253798/1870048, I am using XAMP Server and from that Apache and Tomcat server is been used
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$cartObj = Java("Cart"); //Javav("Cart");
$cartObj->Cart("098765");
$cartObj->setLang("EN");
echo $cartObj->getLang();
but gives error :
Fatal error: Call to undefined function Javav()
What should I exactly I look into?
Also I tried below way also to call the jar file by placing the jar file in my zampp htdoc folder: (D:\xampp\htdocs\jar)
// Using shell_exec
exec('java -jar AutoDiscounts.jar '.$jsonRequest.' 2>&1', $result);
print_r($result);
// Using shell_exec
$arg1 = $jsonRequest;//"My_INPUT_PARAMETER";
$output = '';
$output =shell_exec("java -jar AutoDiscounts.jar $arg1");
echo "Done calling shell exec:";
echo $output;
But both above cases does not give any output .Basically my jar will do some cart processing and return output and it works in the JDevloper
Related
I am trying to run this command in Python:
java JSHOP2.InternalDomain logistics
It works well when I run it in cmd.
I wrote this in Python:
args = ['java',
r"-classpath",
r".;./JSHOP2.jar;./antlr.jar",
r"JSHOP2.InternalDomain",
thisDir+"/logistics"
]
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
proc.communicate()
I have the jar files in the current directory.
but I got this error:
Error: Could not find or load main class JSHOP2.InternalDomain
Does anyone know what the problem is? can't it find the jar files?
You can't count on the current working directory always being the same when running your Python code. Explicitly set a working directory using the cwd argument:
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
cwd='/directory/containing/jarfiles')
Alternatively, use absolute paths in your -classpath commandline argument. If that path is thisDir, then use that:
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
cwd=thisDir)
Following Getting started -
(Windows 7, console: C:...>, .jar & .javauto in the same folder)
java -jar javauto.jar => OK, help is displayed
javauto hello.javauto => command not recognised
javauto.jar hello.javauto => NO result
So i tried this
java -jar javauto.jar -v hello.javauto
Giving this exception (NB: c:...>javac => help display is OK)
Generating ←[92mhello←[0m...
Getting user imports... None
Getting user global variables... None
Getting user functions... None
Generating functions... ←[93mmouseMove ←[0m←[93mmsgBox ←[0m←[93mprint ←[0m←[93msleep ←[0m
Generating class variables... ←[93msimulatedMotionSpeed ←[0m
Generating imports... ←[93mAWTException ←[0m←[93mMouseInfo ←[0m←[93mRobot ←[0m←[93mJDialog ←[0m←[93
mJOptionPane ←[0m
Generating struct objects... None
Generation complete... starting build
Executing cmd /c attrib +s +h "C:\Users\Francis\Develop\java\Javauto\.hello"...
Building ←[92mC:\Users\Francis\Develop\java\Javauto\.hello\class\hello.class←[0m...
Exception in thread "main" java.lang.NullPointerException: Couldn't find java system compiler.
at com.automation.javauto.compiler.CustomJavaCompiler.compile(CustomJavaCompiler.java:36)
at com.automation.javauto.parser.Create.main(Create.java:419)
Try this:
1) Compile it using this command:
java -jar javauto.jar hello.javauto
2) Now that you have compiled your program, there will be a file called hello.jar. Execute with:
java -jar hello.jar
I have Nodejs - server.js code in my windows system from which i want to execute a simple jar file.
So i used follwoing code :
cmd = "java -jar C:\\libs\\sample.jar";
var Exec =exec(cmd, function(error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
}//end of if
});//end of exec cmd
When i run the "node server.js" in command prompt ,jar is executing perfectly.
After this i made this "node server.js" command as service by referring following link :
https://github.com/coreybutler/node-windows
i.e node-windows,But now once its become service i am unable to exectue simple.jar,even i am enble to run simple "java -version" command.
Except java all other command are working fine even after i made nodejs as service.
Please help me out.....
New Update : After testing lot of different cases, Finally i came to know that jars containing JFrame components is not opening...how to solve this
I have two java classes that reside in .../jtest/StepRegTest directory and include "package StepRegTest;" directive.
Option 1. I call it directly from shell:
[jtest]# java StepRegTest.Main
Everything works fine.
Option 2. I call java via PHP exec:
<?php
echo getcwd() . "\n";
exec("java StepRegTest.Main 2>&1", $output);
print_r( $output );
?>
The PHP file is in the same directory jtest as for the Option 1, when I call it from the shell. However, it returns an error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/quinncurtis/matpackjava/DMatBase
The jar archive that refers to these missing classes is in the CLASSPATH.
The import reference for that class is:
import com.quinncurtis.matpackjava.DDMat;
Note that everything works fine when I execute the code from the shell.
What is the problem here? Why does it work from the shell, but not from PHP?
Thanks!
If the CLASSPATH environment variable is being used, verify it's set at the time the php exec() call is made; it may be getting lost.
One easy way to check is this:
<?php
echo getcwd() . "\n";
exec("env", $output);
print_r( $output );
?>
To set the CLASSPATH variable in the php script, the following can be done:
putenv("CLASSPATH=/path/to/lib.jar");
Here's a page that describes putenv():
http://php.net/manual/en/function.putenv.php
I am executing a.jar file from PHP through Command Line. However, if there is any error/exception, the error is not being displayed.
I am using the following PHP script.
<?php
exec('java -jar D:\\ABC\\JavaApplication2\\dist\\JavaApplication2.jar', $result, $returnCode);
var_dump($result);
$count = count($result);
for($i=0; $i<$count;$i++){
print($result[$i]);
}
?>
The output for the above code is : 'array(0) { }'
don't use exec() if you want to handle I/O, instead use popen() for simple stuff (either read or write) or proc_open() for full fd connectivity, with stdin, stdout, stderr, and possibly other fd's connected (e.g. for openssl).
Probably you need to pipe the output of the jar to some file and listen to that file in PHP.