Java command classpath and PHP in Linux

2019-09-08 05:32发布

Hello I have a java jar files and a batch file that I want to run using the java -cp command and from PHP.

My jar files are inside a folder called "jars" in my server and I'm doing as following to run them :

//java.php
$result = exec('java -cp "pack1.jar:pack2.jar" pack3.connect.CommandLine -rb batchfile.odlbat');
echo $result;

This command is working in PHP when all my jar and batch file are in the same folder as my javacall.php file.

Now I want to copy my jar and batch files to a new folder "parent" so I tried to modify the script to load the jar and batch files from the "parent" folder but I get this error :

//java.php
$result = exec('java -cp "parent/pack1.jar:parent/pack2.jar" parent/pack3.connect.CommandLine -rb parent/batchfile.odlbat');
echo $result;

Error : Could not find or load main class parent.pack3.connect.CommandLine

Any help please?

Thanks

2条回答
趁早两清
2楼-- · 2019-09-08 05:48

If you check the documentation for the classpath: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

I think that you must use instead:

java -cp "./parent" parent/pack3.connect.CommandLine -rb parent/batchfile.odlbat
查看更多
贼婆χ
3楼-- · 2019-09-08 06:01

You just need to update the classpath and not the package page path of your main class CommandLine

Change this

parent/pack3.connect.CommandLine

to

pack3.connect.CommandLine
查看更多
登录 后发表回答