如何从 php 执行 java 函数?
How can I execute a java function from php?
我得到了一个具有以下结构的 .jar,可以在 php
中使用
public class encryption
{
public static cryptio encrypt(String user, String password)
{
System.out.println(output);
}
public static cryptio decrypt(String data)
{
System.out.println(output);
}
}
然后我可以使用 php 中的以下代码来访问 jar
<?php echo exec("java -jar encryption.jar 2>&1", $output); ?>
然而这当前输出 'no main manifest attribute, in encryption.jar' 我如何能够指定使用来自 php 的加密和解密函数?
你can't call a non-main method from a JAR file. When you receive the message you're seeing, it means that the JAR hasn't been constructed properly as a main class must be declared. I would suggest creating a wrapper JAR as per this answer.
我得到了一个具有以下结构的 .jar,可以在 php
中使用public class encryption
{
public static cryptio encrypt(String user, String password)
{
System.out.println(output);
}
public static cryptio decrypt(String data)
{
System.out.println(output);
}
}
然后我可以使用 php 中的以下代码来访问 jar
<?php echo exec("java -jar encryption.jar 2>&1", $output); ?>
然而这当前输出 'no main manifest attribute, in encryption.jar' 我如何能够指定使用来自 php 的加密和解密函数?
你can't call a non-main method from a JAR file. When you receive the message you're seeing, it means that the JAR hasn't been constructed properly as a main class must be declared. I would suggest creating a wrapper JAR as per this answer.