My project uses the Maven build manager along with JPA and EclipseLink for interaction with a SQLite databse. The IDE of choice is NetBeans. This question however should not be anchored to the IDE but to the application that is developed in it.
I would like to make my application generate the SQLite database file that it will use in a path relative to the application's location. Is there a way to specify this inside the persistence.xml
or do I have to manually code the procedure of creating the file?
Currently inside the <properties/>
section of my persistence.xml
I have (among other things):
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:/home/user/NetBeansProjects/Cookbook/cookbook_db.sqlite"/>
I have tried for example to replace it with
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:cookbook_db.sqlite"/>
This creates a database file inside my /home
directory however I get permission error when I try to interact with it with my Java application. Entering an absolute path (as in the first example) resolves the problem. Is an absolute path really mandatory?
The behaviour I'm looking for is similar to - let's say - cmake
's CMAKE_BINARY_DIR
. Upon execution cmake
extracts the path from this variable thus allowing the user to alter the binary directory at will. Maven itself supports relative paths in its pom.xml
using the <relativePath/>
tag.
Update: I've added:
<build>
...
<resources>
<resource>
<directory>${basedir}/src/main/resources/META-INF/</directory>
<filtering>true</filtering>
<includes>
<include>persistence.xml</include>
</includes>
</resource>
</resources>
</build>
to my pom.xml
and also changed the JDBC URL property for my SQLite databse file inside my persistence.xml
as suggested by @WillShackleford to:
<property name="javax.persistence.jdbc.url" value="jdbc:sqlite:${basedir}/cookbook_db.sqlite"/>
However now I'm getting:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named CookbookPU
which means that the persistence.xml
is not found.