0
votes

I have a Netbeans project, from which I build a .war file. I now deploy two instances of that war file on my glassfish server, each with a different context root, e.g. mydomain.com/abc and mydomain.com/def

This works fine but they are still operating on the same database, since I declare the persistence unit in the persistence.xml and the glassfish-resources.xml.

My glassfish-resources.xml file:

...
<jdbc-resource  enabled="true"
                jndi-name="jdbc/abc"
                object-type="user"
                pool-name="abcPool">
    <description/>
</jdbc-resource>

<jdbc-connection-pool
    ...
    name="abcPool"
    ...
    <property name="URL" value="jdbc:mysql://localhost:3306/abc"/>
    ...
</jdbc-connection-pool>

My persistence.xml file:

...
<persistence-unit name="abcPU" transaction-type="JTA">
    <jta-data-source>jdbc/abc</jta-data-source>
    ...
</persistence-unit>
...

Does anybody have a solution on how to have two instances of one war file, operating on two different databases?

Is there maybe a way to upload a different glassfish-resources.xml and persistence.xml to each application, overwriting the packaged one?

It would be acceptable to change the module descriptors in the glassfish domain admin console once the application is deployed, if that is possible.

If screenshots from the glassfish domain admin console are needed, please write in the comments, I will add them.

Thank you in advance!

2
Two glassfish applications deployed with one war file What does that mean?Elliott Frisch

2 Answers

0
votes

Easiest approach in my opinion would be to have two different builds.

Basically you may create two different .war files. Each one with a different persistence.xml file in it. One pointing to the JDBC resource ABC and the other one pointing to the JDBS resource DEF.

Build tools like gradle+Jenkins may support you with this.

You will find lots of information about similar tasks, if you search for how to create builds with a different configuration for testing vs. productive system. This is a very common task.

Here might be a starting point for what you are looking for: Create multiple .WAR files with different dependencies in Gradle

0
votes

At server level setup two Data sources pointing to different databases and go to the application instance and modify Resource reference pointing specific data source.