• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, please post the persistence.xml contents.
 
Pierre Sugar
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jaikiran,
thanks a lot!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic