1. Procedure
1. Change the file "dao.properties" and change the position of the comments, so that it points to the remote server:
#-------------------------------------------------------------------------------------------------------------------------------------
#PERSISTENCE UNITS AND HOSTS: 0:Control, 1:Postgres Gexflow1, 2:H2 Sicres ORVE, 3:Postgres Gexflow2, 4:SQL-SERVER Gestio-3 Casdastre, 5:SQL-SERVER Aytos, 6:pg Sicres ORVE
#-------------------------------------------------------------------------------------------------------------------------------------
# 0 1 3 4 5 6 7
persistence.units=control_post;PostgressGexflowJPAPU;sicresh2;sqlserver-gestio3-jtds;sqlserver-aytos-jtds;sicrespg;control_local
#persistence.units=control_local;PostgressGexflowJPAPU;sicresh2;sqlserver-gestio3-jtds;sqlserver-aytos-jtds;sicrespg;control_local
# 0 1 2 3 4 5 6
# pg-Control pg-Gexflow h2-ORVE mssql-Cadatre mssql-Aytos pg-ORVE pg-control_local
persistence.hosts=192.168.28.XX;192.168.28.XX;192.168.10.XX;192.168.28.XX;192.168.28.XX;192.168.28.XX;192.168.10.XX
#persistence.hosts=192.168.10.XX;192.168.28.XX;192.168.10.XX;192.168.28.XX;192.168.28.XX;192.168.28.XX;192.168.10.XX
# 0 1 2 3 4 5 6
persistence.units.active=true;true;false;true;true;true;false
2. Uncomment these 2 dependencies from the pom.xml
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>4.2.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>3.1.4</version>
<scope>runtime</scope>
</dependency>
Take into account that these 2 dependencies are needed if:
- A class a FirtControlLoad is executed from eclipse as a Java application
- When deployed to the WebProp server
But it generates errors when not commented (due to Hibernate Envers) when executed from Eclipse as: Run as ->Run on Server.
3. Verify that the file context.xml in "webapp/METAINF" folder points to the remote DB server IP
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/openweb" docBase="openweb"
debug="5" reloadable="true" crossContext="true">
<!-- url="jdbc:postgresql://localhost:5432/openweb"/> -->
<!-- OJO: Estamos en BDProp 192.168.28.29 -->
<Resource
name="control_post"
auth="Container"
type="javax.sql.DataSource"
username="USER"
password="PASWORD"
maxTotal="50"
maxIdle="20"
maxWait="10000"
timeBetweenEvictionRunsMillis="180000"
removeAbandonedOnMaintenance="true"
removeAbandonedOnBorrow="true"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://192.168.28.XX:5432/openweb"
/>
<!-- Added by Edu @see https://stackoverflow.com/a/19003725/7704658 -->
<!--
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
-->
</Context>
4. Shutdown the tomcat server (tomcat_folder/bin/shutdown.sh)
5. Generate the war : From Eclipse: Run as -> Maven build:
- Goals: clean package
- Profiles: production
6.Copy the file "xxx.war" from the target folder to the tomcat_folder/webapps and rename it to "WEBPROP.war"
7. Start up the tomcat server (tomcat_folder/bin/startup.sh)
8. Optional: If the application cannot run OK, then you should drop the "control" schema from the DBProp Postgress server and re-create it again.
2. Problem solving
1. If the application cannot run OK, then you should drop the "control" schema from the DBProp Postgress server and re-create it again.
2. These error appears:
Caused by: java.lang.NoSuchMethodError: 'org.codehaus.stax2.ri.SingletonIterator org.codehaus.stax2.ri.SingletonIterator.create(java.lang.Object)'
This error is caused because:
a. You have not uncommented the 2 dependencies from org.codehaus.woodstox in step2 and you are using the "WAR file" in the remote tomcat server, or
b. You have not commented on these 2 dependencies in the pom.xml and you are executing the program from eclipse in the local machine