Mohammed Falha
Mohammed Falha

Reputation: 967

Package a runnable JPA jar putting persistence.xml outside

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

Answers (2)

user__42
user__42

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:

vm args in eclipse

Upvotes: 1

Andrei Nicusan
Andrei Nicusan

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

Related Questions