title: How to use SQLite database with path relative to project/application?
body: <p>My project uses the <strong>Maven</strong> build manager along with JPA and EclipseLink for interaction with a SQLite databse. The IDE of choice is <strong>NetBeans</strong>. This question however should not be anchored to the IDE but to the application that is developed in it.</p>
  
  <p>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 <code>persistence.xml</code> or do I have to manually code the procedure of creating the file?</p>
  
  <p>Currently inside the <code>&lt;properties/&gt;</code> section of my <code>persistence.xml</code> I have (among other things):</p>
  
  <pre><code>&lt;property name="javax.persistence.jdbc.url" value="jdbc:sqlite:/home/user/NetBeansProjects/Cookbook/cookbook_db.sqlite"/&gt;
  </code></pre>
  
  <p>I have tried for example to replace it with</p>
  
  <pre><code>&lt;property name="javax.persistence.jdbc.url" value="jdbc:sqlite:cookbook_db.sqlite"/&gt;
  </code></pre>
  
  <p>This creates a database file inside my <code>/home</code> 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?</p>
  
  <p>The behaviour I'm looking for is similar to - let's say - <code>cmake</code>'s <code>CMAKE_BINARY_DIR</code>. Upon execution <code>cmake</code> extracts the path from this variable thus allowing the user to alter the binary directory at will. Maven itself supports relative paths in its <code>pom.xml</code> using the <code>&lt;relativePath/&gt;</code> tag.</p>
  
  <hr>
  
  <p><strong>Update:</strong> I've added:</p>
  
  <pre><code>&lt;build&gt;
  
    ...
  
    &lt;resources&gt;
      &lt;resource&gt;
        &lt;directory&gt;${basedir}/src/main/resources/META-INF/&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
        &lt;includes&gt;
          &lt;include&gt;persistence.xml&lt;/include&gt;
        &lt;/includes&gt;
      &lt;/resource&gt;
    &lt;/resources&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>to my <code>pom.xml</code> and also changed the JDBC URL property for my SQLite databse file inside my <code>persistence.xml</code> as suggested by @WillShackleford to:</p>
  
  <pre><code>&lt;property name="javax.persistence.jdbc.url" value="jdbc:sqlite:${basedir}/cookbook_db.sqlite"/&gt;
  </code></pre>
  
  <p>However now I'm getting:</p>
  
  <pre><code>javax.persistence.PersistenceException: No Persistence provider for EntityManager named CookbookPU
  </code></pre>
  
  <p>which means that the <code>persistence.xml</code> is not found.</p>