简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM