• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to store persistence.xml outside JAR-file?

 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Swing-application connecting to a server using JPA. It happens that the server-hardware is changing and so the IP-address. What I want to do is to change the persistence.xml to point to the new server.

If the persistence.xml is inside the jar I am not able to change it without re-compiling and packaging the application. So the idea is to have persistence.xml outside the JAR-file and change it before starting up the application.

So my questions are:
1. Is it possible to have persistence.xml outside the JAR-file?
2. If yes how to make it available to the application?
3. If no, does anybody know how to accomplish the use case?

I thought this is a common use case, but searching the Internet didn't point to a solution.

Pierre
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't store the persistence.xml outside of the application's package.

It happens that the server-hardware is changing and so the IP-address. What I want to do is to change the persistence.xml to point to the new server.


The IP address of the database server?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, please post the persistence.xml contents.
 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my persistence.xml


So in the above persistence.xml version databaseserver:9002 is the database server accessible within the LAN. If I am traveling (with my notebook PC) and I want to access the database I have to change databaseserver:9002 to something like www.mydomain.com:9002. This I would like to do with starting up a preferences dialog where I can change the database server address without re-compiling and re-JARing.

Any idea?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you running the application standalone or are you running in an application server? For JBoss AS, I know that you can deploy an exploded jar (i.e. like a folder), so you don't have to unjar, edit and re-jar the application. In JBoss AS, you can even have the property value as a placeholder, for example:



and then pass the "DbServer" value as a Java system property:

 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran,
thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic