Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] How to access jndi out of webapp?

Andy,

I'm not quite sure what you're trying to do. Assuming you have something like this in jetty.xml:

 <New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource">
   <Arg></Arg>
   <Arg>jdbc/mydatasource</Arg>
   <Arg>......</Arg>
  </New>


Then you access that in your webapp as:
InitialContext ic = new InitialContext();
ic.lookup("java:comp/env/jdbc/mydatasource");


Outside of that, you can look it up as:
InitialContext ic = new InitialContext();
ic.lookup("jdbc/mydatasource");

Note that only works for jvm-scoped objects. You could look up
objects with other scopes, such as Server too, if you absolutely
needed to. Let me know if you want to do something like that and
I can show you how.

regards
Jan

Michael Zhu wrote:
Hi, all,
I am working on BPMS integration stuff with jetty server, now I get one problem to access jndi. The problem is we want to access the jndi out of webapp. More details for the case: 1): Define the naming resource in jetty.xml with jvm scope or server scope.
    2): Access the jndi with below simple code
    --------------------------------------------------------
System.getProperties().setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi"); System.getProperties().setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
        InitialContext ic = new InitialContext();
Object object = ic.lookup(jndiName); // the jndiName is already defined in jetty.xml
--------------------------------------------------------
The above code will be ok if in one webapp(web context configured), but it will be failed if not within one webapp.

    Is it any way to access the jndi out of the webapp?
Lots of thanks if anyone can help!

Regards,
Andy


------------------------------------------------------------------------

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

--
Jan Bartel, Webtide LLC | janb@xxxxxxxxxxx | http://www.webtide.com


Back to the top