Java command classpath and PHP in Linux

旧巷老猫 提交于 2020-03-06 02:35:28

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/30953552/java-command-classpath-and-php-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!