Jetty 7: configuring JNDI for Start.java

前端 未结 2 580
盖世英雄少女心
盖世英雄少女心 2021-02-09 03:41

Following Wicket 1.5\'s lead, I\'m converting a project from Jetty 6.1.25 to 7.5.0.v20110901. My existing Start.java contains the following setup, which I use to co

相关标签:
2条回答
  • 2021-02-09 03:49

    Starting with Jetty 7, the package name was changed from org.mortbay.jetty to org.eclipse.jetty.

    In addition, org.eclipse.jetty.plus.webapp.Configuration was renamed in version 7.2.0 and the new name is PlusConfiguration. I'm guessing this was done to avoid a name clash with org.eclipse.jetty.webapp.Configuration.

    0 讨论(0)
  • 2021-02-09 04:02

    Put the following into src/test/jetty/jetty-env.xml:

    <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
        <New class="org.eclipse.jetty.plus.jndi.EnvEntry">
        <Arg>jdbc/mydatasource</Arg>
        <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <Set name="Url">jdbc:mysql://localhost/mydatabase?characterEncoding=utf8</Set>
                <Set name="User">username</Set>
                <Set name="Password">password</Set>
            </New>
        </Arg>
        </New>
    </Configure>
    

    Then modify Start.java to define the following properties:

    System.setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");
    System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
    

    And add the following configuration to the WebAppContext:

    EnvConfiguration envConfiguration = new EnvConfiguration();
    URL url = new File("src/test/jetty/jetty-env.xml").toURI().toURL();
    envConfiguration.setJettyEnvXml(url);
    
    bb.setConfigurations(new Configuration[]{ new WebInfConfiguration(), envConfiguration, new WebXmlConfiguration() });
    

    Full details on my blog.

    0 讨论(0)
提交回复
热议问题