I am maintaining a web application that uses java.protocol.handler. I initialize it with a value using: -Djava.protocol.handler.pkgs=<my value>.
The problem is following:
1. If I deploy the app. to tomcat from eclipse directly, using this instruction (directly referring to Tomcat main class) and pass the -Djava.protocol.handler.pkgs=<my value> argument in VM arguments tab, the app works properly and -protocol dependent bean is initialized.
2.If I deploy the .war file directly to Tomcat/webapps and start tomcat with catalina.bat (adding -Djava.protocol.handler.pkgs=<my value> to JAVA_OPTS) I get: Malformed URL supplied Exception.
3.If I start Tomcat from eclipse (and specify VM arguments similar to point 1.) the same .war will be deployed correctly.
My guess is there is difference between how catalina.bat and eclipse initialize VM parameters. Or maybe I should attach my projects .jars to Tomcat somehow.
Thank you for any hints. I can provide more details of required
As per the comments, it’s hard to know what’s going on without more information, but maybe this will help. Tomcat calls
URL.setURLStreamHandlerFactoryto set its ownURLStreamHandlerFactory, which overrides the default behaviour of thejava.protocol.handler.pkgssystem property. You can’t then callURL.setURLStreamHandlerFactorywith your own handler without breaking internal Tomcat functionality. The system of URLStreamHandlers certainly isn’t Java’s greatest feature.The only way I’ve found to reliably use my own stream handler is to pass it into the URL constructor: