Reputation: 967
I want to export my jpa/swing project to a runnable jar. But I want the persistence.xml to be outside the jar not packaged inside, so I can change it without the need to export the jar again after each config.
Upvotes: 4
Views: 2553
Reputation: 573
I had the same problem, but I only needed to change Server, database, user and password. So this did it for me:
In JBoss AS, you can even have the property value as a placeholder, for example:
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://${DbServer}:1234;databaseName=${DbName}" />
<property name="javax.persistence.jdbc.user" value="${DbUser}" />
<property name="javax.persistence.jdbc.password" value="${DbPassword}" />
and then pass the "DbServer", "DbName", "DbUser" and "DbPassword" value as a Java system property:
-DDbServer=sql99 -DDbName=db_Name -DDbUser=USER -DDbPassword=pw
In Eclipse:
Upvotes: 1
Reputation: 4623
According to JPA specifications, persistence.xml
file cannot be detected outside the JAR file where the persistence unit is defined. By convention, it should be placed inside META-INF
directory.
Read JSR-317, paragraph 8.2.1 for more details (http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-eval-oth-JSpec/).
Nevertheless, you can try the hint proposed by this guy here and deploy your archives in exploded form.
Upvotes: 3