3 Replies Latest reply on Feb 21, 2012 9:34 AM by sfcoy

    Database source in root of JBoss

    jso

      Hello,

      I am pretty new at JBoss so the problem I am having might be a trviality for some of you, I am using the JBoss AS 7 version, now, I have a project that was developed in OAS, I already made the deployment of the .ear file in JBoss and it's running ok, the problem I have, is that the project was developed to read the connection string of the database from a XML file that should be located in the root of the server, for example, using OAS in my local machine, I have to place it in C.

       

      The problem that I'm having is that I don't know where should I locate the file so JBoss can read it and run the web page with the data I need, I have looked on the internet with no luck and finally placed the XML file in almost every folder within the JBoss directory, I'm still trying to make it work in my local machine without success.

       

      Has anyone had this problem before? or maybe has an idea of how can I approach it...

      Thanks in advanced

        • 1. Re: Database source in root of JBoss
          sfcoy

          Joan S wrote:

           

          ... is that the project was developed to read the connection string of the database from a XML file that should be located in the root of the server, ..

           

          That is not a portable solution. The usual way of doing this is to

          1. define a datasource in the application server configuration (all enterprise java application servers and even Tomcat support doing this);
          2. inject the javax.sql.DataSource into your code where needed or perform a JNDI lookup to get it;
          3. acquire your java.sql.Connection object from the DataSource.

           

          As you mention that you're new to this I recommend that you have a look at The Java EE 6 Tutorial.

          • 2. Re: Database source in root of JBoss
            jso

            Thank you Stephen, the thing with this project is that it's a little bit old, everything that has to do with the database connection is made in a library which code we don't have (long story, but somebody left this library without the source code), so if I have to change the way this app connects to a database, this means decompiling the library, made the changes, re-compile everything and make the changes in the app that uses this library, if I have no choice I would have to make all the changes, but first I'd like to discard the option in which the app continue working as it works now, this is, reading the database connection from the .xml file.

             

            Thank you very much!

            • 3. Re: Database source in root of JBoss
              sfcoy

              The first thing we need to find out is how the code is accessing the file. ie. Is it:

              1. trying to open the file using java.io.File classes
              2. or trying to access the file as a class loader resource

               

              If the first then you may need to do some decompiling to work out how it's deriving the path to the file.

               

              If it's the second then Loading resource file from ear-file might be helpful.

               

              Is there any kind of stack trace when it fails?