"java.net.MalformedURLException: no protocol" occurred when looking up JNDI binding pointing to the path

Solution unverified - Updated on

Request a new translation or translation update

A translation for your language preference does not exist. Click below to request a translation for your selected language.

Submit request

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

The following JNDI binding is configure to map JNDI to the paths to custom property files:

<subsystem xmlns="urn:jboss:domain:naming:1.4">
   <bindings>
      <simple name="java:/conf/example-conf" value="/path/to/custom/example_app.properties"></simple>
      <simple name="java:/conf/example-log4j-prop" value="/path/to/custom/example_log4j.properties"></simple>
      ...
   </bindings>
   <remote-naming></remote>
</subsystem>

But, when using it from applications, the following Exception was thrown in server.log:

java.net.MalformedURLException: no protocol: /path/to/custom/example_log4j.properties
    at java.net.URL.<init>(URL.java:585)
    at java.net.URL.<init>(URL.java:482)
    at java.net.URL.<init>(URL.java:431)
    ...

Resolution

It indicates it's not valid URL because no protocol is specified to the path. You need to specify URL protocol prefix like "file://" or "http://".

Please modify your binding setting to include protocol prefix "file://". For example:

<subsystem xmlns="urn:jboss:domain:naming:1.4">
   <bindings>
      <simple name="java:/conf/example-conf" value="file:///path/to/custom/example_app.properties"></simple>
      <simple name="java:/conf/example-log4j-prop" value="file:///path/to/custom/example_log4j.properties"></simple>
      ...
   </bindings>
   <remote-naming></remote>
</subsystem>

Root Cause

It's not valid URL because no protocol (e.g. "file://" or "http://", etc) is not specified.

This solution is part of Red Hat's fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.