I am trying to set a JVM argument programmetically in a Ballerina server. I was able to set up the enviroment variable in the terminal but unable to do so, programmatically.
I am trying to set up the jdk.tls.namedGroups enviromment variable with a Ballerina sample server, but the named groups did not change in the TLS handshake.
import ballerina/http;
import ballerina/os;
os:Error? err = os:setEnv("_JAVA_OPTIONS", "-Djdk.tls.namedGroups=secp256r1,secp384r1,secp521r1");
listener http:Listener securedEP = new (9090,
secureSocket = {
key: {
certFile: "./serverpubliccert.crt",
keyFile: "./serverpvtkey.key"
},
protocol: {
name: "TLS",
versions: ["TLSv1.3"]
}
}
);
service / on securedEP {
resource function get greeting(string name) returns string|error {
// Send a response back to the caller.
if name is "" {
return error("name should not be empty!");
}
return "Hello, " + name;
}
}
When I tried setting the environment variable in the terminal, it worked.
export _JAVA_OPTIONS="-Djdk.tls.namedGroups=secp256r1,secp384r1,secp521r1"
AFAIK, _JAVA_OPTIONS env variable is pickedup by JVM itself. Because of that it needs to be there before the JVM started. When you set it inside a ballerina program, the jvm is already started, I'm guessing the Java behavior also is the same.
Is there are any problem with setting the _JAVA_OPTIONS env variable using the terminal for your usecase?