The short answer is that getting JNDI to work is a bit tricky as there are
generally lookup dependencies on the context class loader and for some
servers the lookup must be done by an incoming request thread. Here's an
answer I wrote a ways back that should help but feel free to ask more
questions as needed.

http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg05172.html



|------------>
| From:      |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |Johannes Michler <org...@gmail.com>                                          
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| To:        |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |equinox-dev@eclipse.org                                                      
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Date:      |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |09/10/2009 10:58 AM                                                          
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Subject:   |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |[equinox-dev] injecting Databaseconnection (or -pool) into  servletbridge    
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Sent by:   |
|------------>
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|
  |equinox-dev-boun...@eclipse.org                                              
                                                                     |
  
>--------------------------------------------------------------------------------------------------------------------------------------------------|





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_______________________________________________
equinox-dev mailing list
equinox-dev@eclipse.org
https://dev.eclipse.org/mailman/listinfo/equinox-dev

<<inline: graycol.gif>>

<<inline: ecblank.gif>>

_______________________________________________
equinox-dev mailing list
equinox-dev@eclipse.org
https://dev.eclipse.org/mailman/listinfo/equinox-dev

Reply via email to