Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[equinox-dev] injecting Databaseconnection (or -pool) into servletbridge

Hi,

I wrote a small application using eclipse equinox, that accesses a database using eclipselink JPA and exposes some services using apache CXF. I manged to get this to work using the embedded jetty. In this scenario, the standalone application gets some command-line parameters specifying to which database connect and under what port to expose the http-server. This is fine, so I moved a step further and tried to deploy the same code using the servletbridge into some servlet-containers. After some troubles I managed to get this work for tomcat6 and Oracle 10g app-server (10.1.2). 

For passing the parameters specifying my database, I used the launch.ini in the servletbridge directory to set some environment-variables. But this solution has one mayor drawback: To adapt the jdbc-url I have to edit the  launch.ini, make a new .war and deploy this .war on my app-server. 
Is there a way to do this more conveniently? I'm new to application servers, here is what I tried so far:


But how do I get the jdbc-connection from within my eclipse-application? I'm doing the following to get the httpService in my Activator:
ServiceReference reference = context.getServiceReference( HttpService.class.getName());

        HttpService httpService = null;
        if ( reference != null)
            httpService = ( HttpService) context.getService( reference);

To get the db-connection I tried the following code from the tomcat-6 documentation (http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html):

try {
        javax.naming.Context initContext = new javax.naming.InitialContext();
        javax.naming.Context envContext  = (javax.naming.Context)initContext.lookup("java:/comp/env");
        javax.sql.DataSource ds = (javax.sql.DataSource)envContext.lookup("jdbc/myoracle");
        
            java.sql.Connection conn = ds.getConnection();
        } catch ( SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch ( NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

But this didn't work. Tomcat6 complained about "java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory" and OC4J reported it could not find the java:/comp/env context.

Any hints on how to solve this? 


Best regards
-orgler

Back to the top