I have a Lotus Notes database which is performing some interaction with a remote web service. I've written a custom Java class to perform the interaction.

The class methods can be executed from one of three locations depending on the user's setup:

  1. Within a Java script library called via a Lotus Notes Java agent
  2. Within a JAR file located in the user's "jvm/lib/ext" directory
  3. Within a JAR file located in a custom directory within the user's "jvm/lib" directory (for example, "jvm/lib/custom_dir"). The Lotus Notes JVM is aware of the custom directory via usage of the "JavaUserClassesExt" local notes.ini variable.

Within my class I would simply like to be able to return the location the current class is executing from. So if it's executing from either option 2 or option 3, then return the JAR file path. If it's executing from option 1 then return something else which I can handle.

I've tried the following.

getProtectionDomain() method

getClass().getProtectionDomain().getCodeSource().getLocation()

Which results in:

java.security.AccessControlException: Access denied (java.lang.RuntimePermission getProtectionDomain)

There is no option to change any security settings on any clients running this.

Class.getResource method

String myName = "/" + getClass().getName().replace('.', '/') + ".class";
URL myResourceURL = getClass().getResource(myName);

Result: myResourceURL is ALWAYS null.

ClassLoader.getResource method

String myName2 = getClass().getName().replace('.', '/') + ".class";
ClassLoader myCL = getClass().getClassLoader();
URL myResourceURL2 = myCL.getResource(myName);

Result:

Edit
Report