Reputation: 6678
i'm developing a webapp made up with 2 other maven modules.
i have the model module which representes database layer.it has spring application context test-model-config.xml
in test/resources/META-INF
for testing and the properties files in test/resources' default package
. and model-config.xml
in resources/META-INF
which is the live context and which is supposed to pick properties from the webapp.
up to now builds fine, works fine no problem
- <!-- test-model-config.xml and model-config.xml have the same thing-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
here is just a snippet of the properties in test/resources
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.username=sa
jdbc.password=
jdbc.url=jdbc:hsqldb:file:target/mydb;create=true
there is another module services which has the same kind of conf where there is a test config and a live config files.this one too separately has no problem.builds fine , works fine.
now the webapp there is webapp-config.xml
in /web pages/WEB-INF
and general.properties
for all the properties needed for model and service modules. so general.properties
and webapp-log4j.properties
are in resources' default package
of the webapp.here a snippet of webapp-config.xml
<import resource="classpath:META-INF/model-config.xml" />
<import resource="classpath:META-INF/service-config.xml" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:general.properties</value>
<value>classpath:webapp-log4j.properties</value>
</list>
</property>
</bean>
in the general.properties we have
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.username=sa
jdbc.password=
jdbc.url=jdbc:hsqldb:file:classpath:target/mynewdb;create=true
// ....
it also builds fine and runs fine with an issue.
1 : the log says:
java.sql.SQLException: File input/output error classpath:target/mynewdb.properties java.io.FileNotFoundException: classpath:target/mynewdb.properties.new (No such file or directory) full debug output is here
i'm really surprised because this is the first time i'm facing this kind of error.it's running fine with a absolute url as /media/Repo/myproject/mydb;create=true
, but the idea is to have it in the the webapp target so that it got deleted when target folder is being deleted.
well i have no clue and it's been 2 days now. How can id fix this? is here something i'm not seei/doing? is it due to maven configuration? my pom is viewable here thanks for reading this.
Upvotes: 4
Views: 3637
Reputation: 1210
My HSQLDB file database is working by using the following JDBC URL:
jdbc:hsqldb:res:/db/mydb
Where mydb is the name of the HSQLDB file and is located in the following directory:
/WEB-INF/classes/db
Upvotes: 0
Reputation: 10381
The database file path is relative to the current working directory of your JVM.
In the case you run your JVM from Maven sunfire plugin (for instance), you have to set the property workingDirectory
(or corresponding option of any other plugin).
You may use res:
mode instead of file:
to get your database from classpath but it is limited to a read-only access.
Upvotes: 1