2 Replies Latest reply on Feb 27, 2017 5:01 AM by Benedict Leahy

    Windup report InitialContext lookup

    Benedict Leahy Newbie

      Hi there,


      I'm going to through the mandatory incidents of my Windup report migrating from Jboss 5 to Jboss 7.


      So before I made  any changes to our Java scripts I ran the windup tool and it obviously found reference to the datasources from the original oracle-ds.xml file.




      From oracle-ds.xml




      So I updated the Java script with what I believe is the correct syntax for the initialContext.lookup for JBoss 7 compliance with reference to my new datasource from my standalone.xml and the Windup tool is still highlighting the syntax as a problem.

      I think initCtx.lookup is ok but I'm new at this. Can I use the following call to the datasource in JBoss 7.1.1 ?  If I need to provide more information , just let me know. Kind regards Ben


      try {
      initCtx = new InitialContext();
      DataSource e = null;

      try {
      e = (DataSource)initCtx.lookup("java:jboss/datasources/jdbc/CLIENT/SYSTEM");



      From standalone.xml


        • 1. Re: Windup report InitialContext lookup
          Anup Dey Expert



          Follow the below steps:


          Install a JDBC driver as a core module:


          1.Create a directory under $JBOSS_HOME/modules. In this example: "$JBOSS_HOME/modules/com/oracle/jdbc/main".

          2.Put the the JDBC driver jar (ojdbc6.jar) in this directory

          3.Create a module configuration file module.xml:



          <module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc">


              <resource-root path="ojdbc6.jar"/>



              <module name="javax.api"/>

              <module name="javax.transaction.api"/>





          Note that the jdbc driver jar must contain a META-INF/services/java.sql.Driver text file that specifies the jdbc Driver, otherwise the Java service provider mechanism used to load the driver will not work. From the main/common vendors only Informix does not have this out of the box.



          Configure a datasource setting in standalone.xml or domain.xml:


          You can now edit your standalone(-*).xml or domain(-*).xml to configure a datasource that references this module:



            <subsystem xmlns="urn:jboss:domain:datasources:1.2">


                <datasource jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="true">














                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"></valid-connection-checker>

                    <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"></stale-connection-checker>

                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"></exception-sorter>




                  <driver name="oracle" module="com.oracle.jdbc">








          JNDI name for datasource can be configured using java:/xxxx or java:jboss/xxxx.

          The above two JNDI names are supported for datasource in JBoss EAP 6.

          Using the JNDI name java:jboss/xxxx for datasource is the preferred way.



          Look up daatsource inside Java scripts or JSP:



          Connection con=null;

          DataSource ds=null;




            Context ctx=new InitialContext();



                  System.out.println("Got DataSource ds  = " + ds);

                  out.println("Got DataSource : = " + ds);

                  System.out.println("Looking Up an Object in the JNDI tree...");


                 con = ds.getConnection();                  

                 out.println("Got Connection  : " + con);

                 System.out.println("Got Connection  : " + con);


               } catch(Exception e) {


               } finally {

                 try {

                          if (con != null && !con.isClosed()) {



                      } finally {

                           con = null;



          • 2. Re: Windup report InitialContext lookup
            Benedict Leahy Newbie



            I think you've answered my question in a round about way. In that syntactically I can use e = (DataSource)initCtx.lookup("java:jboss/datasources/jdbc/CLIENT/SYSTEM");      in my java code.


            And that the Windup report is producing a false positive. It would be nice if someone could confirm that. Remember this is jboss AS 7.1.1




            try {
                     initCtx = new InitialContext();
                     DataSource e = null;

                     try {
                         e = (DataSource)initCtx.lookup("java:jboss/datasources/jdbc/CLIENT/SYSTEM");

            From standalone.xml

            <datasource jta="true" jndi-name="java:jboss/datasources/jdbc/CLIENT/SYSTEM" pool-name="jdbc/CLIENT/SYSTEM" enabled="true" use-ccm="false">