I want to run Java file from Golang code.
Java File: Only for testing purpose.
public class AuthBridge {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
if(args.length != 3){
return;
}
String keyRecived = args[0];
String pubKey = args[1];
String mode = args[2];
System.out.println("Here" + keyRecived + " " + pubKey + " " + mode);
if(new String(mode).equals("decrypt")){
String response = new AuthBridge().Decrypt(keyRecived, pubKey);
System.out.println(response);
}else{
return;
}
} catch (Exception exc) {
System.out.println(exc.getMessage());
}
}
public String Decrypt(String input, String key){
return "Testing";
}
}
Golang Code Test Function only
import (
"fmt"
"os/exec"
"testing"
)
func TestEncryption(b *testing.T) {
cmd := exec.Command("java", "AuthBridge", "KeyRecived", "PublicKey", "decrypt")
fmt.Println("cmd args:", cmd.Args)
output, _ := cmd.CombinedOutput()
fmt.Println("Output:", string(output))
}
Problem: When I run the go test file it shows me error
Output shows me error of class not found exception.
cmd args: [java AuthBridge KeyRecived PublicKey decrypt]
Output: Error: Could not find or load main class AuthBridge
Caused by: java.lang.ClassNotFoundException: AuthBridge
Anyone please help me with this? Thanks