Replying to myself.
I found the solution. I needed to set the attribute
"org.eclipse.jetty.webapp.configuration" in the embedded server.
So here goes:
String[] conf = new String[] {
"org.eclipse.jetty.webapp.WebInfConfiguration",
"org.eclipse.jetty.webapp.WebXmlConfiguration",
"org.eclipse.jetty.webapp.MetaInfConfiguration",
"org.eclipse.jetty.webapp.FragmentConfiguration",
"org.eclipse.jetty.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.plus.webapp.PlusConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration",
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.webapp.TagLibConfiguration"};
server.setAttribute("org.eclipse.jetty.webapp.configuration", conf);
On Mon, Dec 13, 2010 at 2:39 PM, Filipe Sousa <[email protected]> wrote:
> Hi,
>
> I'm using the following code to run jetty:
>
> public class JettyServer {
> private final static String PATH = System.getProperty("user.dir");
>
> public static void main(String[] args) throws Exception {
> System.setProperty("jetty.home", PATH);
>
> Server server = new Server(8080);
>
> ContextHandlerCollection contexts = new ContextHandlerCollection();
> server.setHandler(contexts);
>
> DeploymentManager dm = new DeploymentManager();
> dm.setContexts(contexts);
> server.addBean(dm);
>
> ContextProvider provider = new ContextProvider();
> provider.setMonitoredDirName(PATH + "/contexts");
> provider.setScanInterval(1);
> dm.addAppProvider(provider);
>
> server.setStopAtShutdown(true);
> server.start();
> server.join();
> }
> }
>
> And I have my servlet defined as:
>
> public class HelloServlet extends HttpServlet {
> private static final long serialVersionUID = 1L;
>
> private static final String DATA_SOURCE = "jdbc/webdocs";
>
> @Resource(name = DATA_SOURCE)
> private DataSource ds1;
>
> @Override
> protected void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
> try {
> Context ctx = new InitialContext();
> DataSource ds2 = (DataSource) ctx.lookup(DATA_SOURCE);
>
> PrintWriter w = resp.getWriter();
> w.println("ds1: " + ds1);
> w.println("ds2: " + ds2);
> } catch (NamingException e) {
> throw new ServletException(e);
> }
> }
> }
>
> And the jetty-web.xml file has the following:
>
> <?xml version="1.0"?>
> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "
> http://www.eclipse.org/jetty/configure.dtd">
> <Configure class="org.eclipse.jetty.webapp.WebAppContext">
> <New id="webdocs" class="org.eclipse.jetty.plus.jndi.Resource">
> <Arg>jdbc/webdocs</Arg>
> <Arg>
> <New class="oracle.jdbc.pool.OracleDataSource">
> <Set name="URL">jdbc:oracle:thin:@localhost:1521:integra</Set>
> <Set name="User">publicar_dev</Set>
> <Set name="Password">????</Set>
> </New>
> </Arg>
> </New>
> </Configure>
>
> Now, my problem is that when I go to http://localhost:8080/hello I get:
>
> ds1: null
> ds2: oracle.jdbc.pool.oracledatasou...@94af2f
>
> In this case the @Resource (name = data_source) is not working.
> I have jetty-annotations in my class path and I'm using
> jetty-7.2.2.v20101205 for Linux
>
> I have used this approach with Tomcat and Glassfish with great success, but
> I'm not getting the same with the jetty.
>
> Thanks.
> --
> Filipe Sousa
>
--
Filipe Sousa
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users