3 Replies Latest reply on Oct 1, 2003 4:56 PM by malyg

    overriding default JNDI context for a datasource

    malyg Newbie

      Is there a way to deploy a datasouce without the VM context "java:/"

      I am trying do deploy a data source in JBoss 3.2.0 under a jndi-name - "jdbc/MyDatasource", however JBoss deploys it under "java:/jdbc/MyDatasource". The documentation says that it does it because a datasource should only be available for a particular VM and therefore only belongs to that VM's context.
      In my case, however, the datasource name has to be "jdbc/MyDatasource" - without the context part.( The reason - I am deploying to an Weblogic production instance that has a datasource named "jdbc/MyDatasource" and have to way of changing this, and would like to have dev. evironment to be exacly the same).
      Thank you for any advice on this really frustrating matter.
      -alex

        • 1. Re: overriding default JNDI context for a datasource
          micke Novice

          Use reference to look up DataSource and you dont need to care about deploy JNDI name.

          J2EE
          <!-- JDBC DataSources (java:comp/env/jdbc) -->
          <resource-ref>
          My Data Source
          <res-ref-name>jdbc/MyDatasource</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>

          WEBLOGIC
          <resource-description>
          <res-ref-name>jdbc/MyDatasource</res-ref-name>
          <jndi-name>yourDeployName</jndi-name>
          </resource-description>

          JBOSS
          <resource-ref>
          <res-ref-name>jdbc/MyDatasource</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <jndi-name>yourDeployName</jndi-name>
          </resource-ref>

          Source (works on WL and JBOSS) :
          Context ctx = new InitialContext();
          DataSource ds = (DataSource)initial.lookup("java:comp/env/jdbc/MyDatasource");

          /micke

          • 2. Re: overriding default JNDI context for a datasource
            malyg Newbie

            Thanks micke, that works!

            Also it seems that JBoss deploys the same datasource
            under "java:comp/evn/jdbc/MyDatasource", which works in my case since Weblogic also deployed the datasouce under that name.

            So, from what I've seen one can say that:

            If you deploy a datasource with a name "jdbc/MyDatasouce" it can be located under the following names.

            In Jboss - under "java:/jdbc/MyDatasouce" or under "java:comp/env/jdbc/MyDatasource"

            In Weblogic - under "jdbc/MyDatasource" and "java:comp/env/jdbc/MyDatasouce"

            Note: "java:comp/env" is the J2EE "recomended" component evrionement context, as far as I understand.

            -alex

            • 3. Re: overriding default JNDI context for a datasource
              malyg Newbie

              Never mind the last post. JBoss did not deploy my datasource under "java:comp/env".

              micke's solution seems to be the only one that works
              in my case.

              My appologies.

              -alex