Frage

I use Jetty to launch some webapps which connect to file-based databases on a HSQLDB server. Those databases files are in the directory project/hsqldb-1.8.0.10/hsqldb/ and my webapps are in project/jetty/webapps/.

To connect to the database, I need to set the property url of org.apache.commons.dbcp.BasicDataSource. I need to use a relative path because the goal of all that is to deploy my webapps on every computer, so directories will be at different locations, but always in project/.

This was my first try:

<property name="url" value="jdbc:hsqldb:file:../../hsqldb-1.8.0.10/hsqldb/myDatabase"/>

I used ../../ as jetty/webapps/ to be placed in project directory. But it doesn't work, the identification failed because the webapp didn't find the user. Obviously, it's because it wasn't connected to the right database.

How to set the relative path correctly?

War es hilfreich?

Lösung

The database file is not found because the starting directory isn't jetty/webapps/, it's the directory from where Jetty is launched.

In my case, I did:

cd jetty
java -jar start.jar

So, the right relative path is:

jdbc:hsqldb:file:../hsqldb-1.8.0.10/hsqldb/myDatabase

That solved the issue.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top