Hi Troy, I guess you've already seen the doco page here:
http://wiki.eclipse.org/Jetty/Feature/JNDI Basically, anything you can do in xml in jetty you can do in code. The Resource definition you've got above will appear in the namespace visible across the jvm. That should be fine for your purposes. If you want to restrict it to only being visible to a particular Server or WebAppContext instance, then you need provide that object as the first argument to the constructor. In order to do that, unless you're constructing the WebAppContext programmatically too, then you'll need to define your datasource back in the jetty-env.xml file. So you'll need to store the value of the dbUri from the code above somewhere it can be referenced by the jetty-env.xml. Some alternatives are: put it as an attribute on the Server instance and then retrieve it in the jetty-env.xml file using the "server" Ref; or put it into a System property; or put it into some object that is visible both external to the webapp and internal to the webapp. cheers Jan On 11 January 2013 11:53, Troy Sellers <[email protected]> wrote: > Hi, > > I am trying to run embedded Jetty for Heroku deployment. Have configured a > datasource using jetty-env.xml in the web app but I want to apply database > url from environment string stored in my heroku app environment. > > I am trying this in my Main class .. but I am not sure if this is correct > or how I apply this Resource object to the WebAppContext? > > //configure database properties > > URI dbUri = new URI(System.getenv("DATABASE_URL")); > > > String username = dbUri.getUserInfo().split(":")[0]; > > String password = dbUri.getUserInfo().split(":")[1]; > > String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + > dbUri.getPort() + "/" + dbUri.getPath(); > > > > logger.info("DBURI ["+dbUri+"]"); > > logger.info("Username ["+username+"]"); > > logger.info("Password ["+password+"]"); > > logger.info("Host ["+dbUri.getHost()+"]"); > > logger.info("Port ["+dbUri.getPort()+"]"); > > logger.info("Path ["+dbUri.getPath()+"]"); > > > > logger.info("DBRUL ["+dbUrl+"]"); > > > > PGSimpleDataSource pgDS = new PGSimpleDataSource(); > > pgDS.setDatabaseName(dbUri.getPath()); > > pgDS.setUser(username); > > pgDS.setPassword(password); > > pgDS.setServerName(dbUri.getHost()); > > pgDS.setPortNumber(dbUri.getPort()); > > > > Resource resource = new Resource("jdbc/obmDS", pgDS); > > -- > "A computer lets you make more mistakes faster than any other invention in > human history, with the possible exceptions of handguns and tequila." > - Mitch Ratcliffe > > _______________________________________________ > jetty-users mailing list > [email protected] > https://dev.eclipse.org/mailman/listinfo/jetty-users > > -- Jan Bartel <[email protected]> www.webtide.com – Developer advice, services and support from the Jetty & CometD experts.
_______________________________________________ jetty-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/jetty-users
