If you try the declare in a new RDBMS session I believe you will find that it works. Or insert the line
between the dbms_java.set_property and the getEnvironmentVar call. When dbms_java.set_property is called, it establish a value for a property that is only used in subsequent initializations of the java VM during the current RDBMS session. It does not affect the java VM that has already been initialized in the session, if any. If java has not been used before in the current session, then the VM will be initialized when the getEnvironmentVar call is done and the value established earlier by dbms_java.set_property will be seen. But if java had already been in use in the session, such as would happen if you had earlier created or resolved the class containing the method getEnvironmentVar in that session, then the value set by dbms_java.set_property will not be seen (unless and until something (like dbms_java.endsession, System.exit or some fatal error) occurs to terminate the existing java VM without terminating the RDBMS session).