简体   繁体   English

如何从php执行Java函数?

[英]How can I execute a java function from php?

I have been given a .jar with the below structure to use in 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);
    }
}

I am then able to use the following code in php to access the jar 然后,我可以在php中使用以下代码来访问jar

<?php echo exec("java -jar encryption.jar 2>&1", $output); ?>

However this currently outputs 'no main manifest attribute, in encryption.jar' how am I able to specify to use the encrypt and decrypt functions from php? 但是,这目前输出'nomain manifest attribute,in encryption.jar'我如何能够指定使用php的加密和解密功能?

You can't call a non-main method from a JAR file. 不能从JAR文件中调用非主要方法 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. 当您收到所看到的消息时,这意味着JAR 尚未正确构建,因为必须声明一个主类。 I would suggest creating a wrapper JAR as per this answer . 我建议根据此答案创建包装JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM