Question

What I want is when Jetty starts, it creates a database which can be used by my webapps. My goal is to be able to deploy my webapps on every computer to display my application.

I need a way to declare my HSQLDB database (I've SQL-files for all my databases to set up the structure and to fill it with datas) in the Jetty configuration. Those parameters just have to be set one time and won't change in the future.

I feel like I've looked for it everywhere and tried everything but nothing wants to work :( I'm using Jetty 9 by the way.

This is one of the option I've tried and which seems to be close to my solution to me. I added this code to jetty/etc/jetty.xml

<New id="toto" class="org.eclipse.jetty.plus.jndi.Resource">
  <Arg></Arg>
  <Arg>jdbc/toto</Arg>
  <Arg>
    <New class="org.apache.commons.dbcp.BasicDataSource">
      <Set name="DriverClassName">org.hsqldb.jdbc.jdbcDataSource</Set>
      <Set name="Url">jdbc:hsqldb:hsql://localhost:9015/toto</Set>
      <Set name="Username">toto</Set>
      <Set name="Password">toto</Set>
    </New>
  </Arg>
</New>

and this one to jett/etc/webdefault.xml

<resource-ref>
  <res-ref-name>jdbc/toto</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

Merry Christmas to anyone who can help me :)

Edit 26/12/2013 : Another option I tried is to configure the database through spring in Eclipse. Each webapp matches a project (maven architecture) and use its own database. Thus, for one project I did this :

*conf/common/resources/applicationContext.xml (Project)

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
  <property name="url" value="jdbc:hsqldb:mem:toto"/>
  <property name="username" value="toto"/>
  <property name="password" value="toto"/>
</bean>

*conf/dev/WEB-INF/web.xml (Project)

<resource-ref>
  <res-ref-name>jdbc/toto</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

*conf/dev/WEB-INF/jetty-web.xml (Project)

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="square" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref id="wac" /></Arg>
    <Arg>jdbc/square</Arg>
    <Arg>
     <New class="org.hsqldb.jdbc.jdbcDataSource">
       <Set name="Database">file:square</Set>
       <Set name="User">${database.connection.username}</Set>
       <Set name="Password">${database.connection.password}</Set>
      </New>
    </Arg>
  </New>
</Configure>

*jetty/start.ini (Jetty) : Uncomment these lines

OPTIONS=jndi
OPTIONS=plus
etc/jetty-plus.xml

With all that, I get this exception :

java.lang.ExceptionInInitializerError
at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:159)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:812)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1322)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:732)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:490)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:282)
at org.eclipse.jetty.util.component.ContainerLifeCycle.addBean(ContainerLifeCycle.java:214)
at org.eclipse.jetty.util.component.ContainerLifeCycle.updateBeans(ContainerLifeCycle.java:764)
at org.eclipse.jetty.server.handler.HandlerCollection.setHandlers(HandlerCollection.java:89)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.setHandlers(ContextHandlerCollection.java:145)
at org.eclipse.jetty.server.handler.HandlerCollection.addHandler(HandlerCollection.java:155)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:41)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:495)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:175)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:605)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

EDIT 07/01/2014

I gave up on that path but I succeeded to do what I want here: Connect databases to HSQLDB Server

No correct solution

OTHER TIPS

It looks like you are using your HSQLDB as an embedded database, but are trying to connect to it in the server mode. Please check out the following documentation for the correct JDBC connection string when running HSQLDB in the embedded mode: http://hsqldb.org/doc/guide/running-chapt.html#rgc_inprocess

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top