Chimeara
Chimeara

Reputation: 695

How can I execute a java function from php?

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

Upvotes: 0

Views: 1141

Answers (1)

Catchwa
Catchwa

Reputation: 5855

You 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.

Upvotes: 1

Related Questions