Preciso modificar o valor de uma variável de ambiente, contudo utilizar o @Value e alterar no application.properties estão fora de questão.
Acabei me deparando com estes dois métodos, contudo ambos me retornar que o valor armazenado é "null".
Método 1
private static Map getModifiableEnvironment() throws Exception{
        Class pe = Class.forName("java.lang.ProcessEnvironment");
        Method getenv = pe.getDeclaredMethod("getenv");
        getenv.setAccessible(true);
        Object unmodifiableEnvironment = getenv.invoke(null);
        Class map = Class.forName("java.util.Collections$UnmodifiableMap");
        Field m = map.getDeclaredField("m");
        m.setAccessible(true);
        return (Map) m.get(unmodifiableEnvironment);
    }
    private static void environmentSet() throws Exception {
        getModifiableEnvironment().put("minhaVariavel", "umValor");
        System.out.println(System.getenv("minhaVariavel"));
        }Método 2
  /*  private static void set_up_environment_var() throws IOException{
        try {
            Process process = Runtime.getRuntime().exec("set", new String[]{"minhaVariavel=umValor"});
            System.out.println(System.getenv("minhaVariavel"));
            BufferedReader stdInput = new BufferedReader(new
                    InputStreamReader(process.getInputStream()));
            BufferedReader stdError = new BufferedReader(new
                    InputStreamReader(process.getErrorStream()));
            System.exit(0);
        }
        catch (IOException | InterruptedException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }Alguma sugestão de como modificar essa variável ?
 
            