I have an applet that needs to call JAXP, specifically SAXParserFactory. Now, as you can see from the Javadoc, this internally uses the Service Provider mechanism as documented here:
Specifically, if it does not find a file in any of my application JARs called META-INF/services/javax.xml.parsers.SAXParserFactory
it will try to fetch it from my application codebase. If I have my applet deployed as follows:
<applet code="com.example.applets.MyApplet"
codebase="http://www.example.com/myapp/" archive="myapp.jar, dom4j.jar">
Then it will try to make an HTTP request to http://www.example.com/myapp/META-INF/services/javax.xml.parsers.SAXParserFactory
I'd rather it not do that, specifically because my applet is signed and this additional HTTP call triggers a warning about unsigned code.
Now, the obvious solution is to just put the META-INF/services file in my application JAR like it says, but how do I do that yet still get it to use the user's JRE default implementation of JAXP? Alternately, is there a way to convince the applet runtime to look only in my JAR files and not in the codebase
for that file?
Note: I know I could also deploy my own copy of JAXP-RI but that's pretty heavy-weight for an applet.
Disable the codebase lookup:
The
AppletClassLoader
checks for a boolean propertysun.applet.AppletClassLoader.codebaseLookup
, which can be influenced by setting the above parameter. The methodsun.applet.AppletPanel.init()
will read the parameter and set it into theAppletClassLoader
. Once disabled, the AppletClassLoader will stop making remote lookups for classes and resources in the codebase, that is the URL given bycodebase="http://www.example.com/myapp/"
and only look into the archives and system class paths.Note: I did not test this myself, but according to code review in the disassembled code, i honestly believe it could work.
It's also documented in JavaSE - Technical Notes - Plugin Developer Guide - Special Attributes: