Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to read environment variable in persistence.xml
    primarykey
    data
    text
    <p>I have a Maven3 project where I'm using the tomcat7-maven-plugin. I would like to set the path for the embedded database via an environment variable argument to the jvm.</p> <p>Reading the variable with System.getenv("myDataDir") within a Java-Method returns the correct path. But when I try to set the variable ${myDataDir} in my persistence.xml and then I start tomcat with "mvn tomcat:run" I get FileNotFoundExceptions because the variable is not replaced with the actual value (it says e.g. Cannot find path for ${myDataDir}\derby.log)</p> <p>I don't know what's causing this - if it's the persistence provider (EclipseLink) that doesn't support this or if it's something else.</p> <p>My persistence.xml looks like this:</p> <pre><code>&lt;persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"&gt; &lt;persistence-unit name="myPersistence" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt; &lt;properties&gt; &lt;property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" /&gt; &lt;property name="javax.persistence.jdbc.url" value="jdbc:derby:${myDataDir}/DB;create=true;upgrade=true" /&gt; &lt;property name="javax.persistence.jdbc.user" value="admin" /&gt; &lt;property name="javax.persistence.jdbc.password" value="password" /&gt; &lt;property name="eclipselink.ddl-generation" value="create-tables" /&gt; &lt;property name="eclipselink.ddl-generation.output-mode" value="both" /&gt; &lt;property name="eclipselink.logging.level" value="SEVERE" /&gt; &lt;property name="eclipselink.logging.file" value="${myDataDir}/derby.log" /&gt; &lt;property name="eclipselink.application-location" value="${myDataDir}/dbScripts" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <h2>EDIT:</h2> <p>I forgot to mention, that I'm in a Spring 3 Framework environment. According to the examples on the web, this should be capable of using environment variables in persistence.xml...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload