1 Reply Latest reply on Sep 19, 2016 2:11 PM by Bere De la luz

    how to read standalone.xml file dinamically at runtime in jboss eap 6.2 application?

    Carlos Esteban Gil Newbie

      I need to read all datasources data defined in standalone.xml at runtime, I need server, user, pass etc (all the data) to connect manually ( via jdbc or whatever ) to each datasource.

      for example, if I 've a file : standalone.xml like this: ( with 2 datasources def .. )

      <xa-datasource jndi-name="java:jboss/datasources/MyDS1" pool-name="MyDSPool1" enabled="true">

      <xa-datasource-property name="URL"> jdbc:mysql://localhost:3306/mydb </xa-datasource-property> <driver>mysql</driver>

      <security> <user-name>myuser</user-name> <password>mypass</password> </security>





      <xa-datasource jndi-name="java:jboss/datasources/MyDS2" pool-name="MyDSPool2" enabled="true">

      <xa-datasource-property name="URL"> jdbc:mysql://localhost:3306/mydb </xa-datasource-property> <driver>mysql</driver>

      <security> <user-name>root</user-name> <password>root</password> </security>


      then .. in my EAP application, in my servlet ( the entry point to my EAP app ) , I need to read standalone.xml ( the physical file ) and then get each datasource info and connect to each db. ( I don't need to inject the datasource in an EJB class of any EJB module, I just need to read standalone.xml dinamically ( at runtime ) and via jdbc connect to each datasource . And I need to read/loop all datasources defined in standalone.xml and connect to each one via jdbc at that moment (in the servlet ) I know how to use datasources via annotations or jndi in ejb classes, but I really need to ,first, open/read standalone.xml (with getResourceAsStream? or anything like that ) and connect to each datasource defined in it ( all possible datasources that application could use ) , connect to each one via jdbc for example ) and do some checks!.

      So basically what I need is : dinamically access/read StandAlone.xml, (all Datasources Data) , in the servlet. parse it or something, get all datasources definitions, connect to each datasource via jdbc using this data readed from the standalone.xml, do some checks, and nothing more. I sthat possible? I am Using Jboss EAP 6.2.