4

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.

Andrei Nicusan
  • 4,555
  • 1
  • 23
  • 36
Mohammed Falha
  • 967
  • 8
  • 22

2 Answers2

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
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:

vm args 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