简体   繁体   English

打包一个可运行的JPA jar,将persistence.xml放在外面

[英]Package a runnable JPA jar putting persistence.xml outside

I want to export my jpa/swing project to a runnable jar. 我想将我的jpa / swing项目导出到一个可运行的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. 但是我希望persistence.xml在jar里面没有打包,所以我可以在不需要在每次配置后再次导出jar的情况下更改它。

According to JPA specifications, persistence.xml file cannot be detected outside the JAR file where the persistence unit is defined. 根据JPA规范,在定义持久性单元的JAR文件之外无法检测到persistence.xml文件。 By convention, it should be placed inside META-INF directory. 按照惯例,它应该放在META-INF目录中。

Read JSR-317, paragraph 8.2.1 for more details ( http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-eval-oth-JSpec/ ). 有关详细信息,请阅读JSR-317第8.2.1段( 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: 在JBoss AS中,您甚至可以将属性值作为占位符,例如:

<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: 然后将“DbServer”,“DbName”,“DbUser”和“DbPassword”值作为Java系统属性传递:

-DDbServer=sql99 -DDbName=db_Name -DDbUser=USER -DDbPassword=pw

In Eclipse: 在Eclipse中:

vm args in eclipse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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