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.
Asked
Active
Viewed 2,440 times
2 Answers
3
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.

Andrei Nicusan
- 4,555
- 1
- 23
- 36
-
Thx, for the specifications note, but regarding the answer in your link what does the meaning of exploded form. – Mohammed Falha Nov 16 '13 at 22:12
-
It seam it mean to have an application server(exploded form) – Mohammed Falha Nov 16 '13 at 22:13
1
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:

user__42
- 543
- 4
- 13
-
The java system property tricks also works for packaged JavaFX applications. The JVM properties are stored in the `app/your-app-name.cfg` file – amrtn Mar 29 '19 at 12:51