2 Replies Latest reply on Nov 6, 2019 7:12 AM by gennari-dkt

    wildfly-maven-plugin usage

    gennari-dkt

      Hi there,

      I am trying to use wildfly-maven-plugin with a Spring MVC application in Netbeans IDE. I need to add a postgresql resource to Wildfly (version 16 at the moment) before deploy my application.

       

      I am using this pom:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>it.diakont</groupId>
          <artifactId>DiakontEE</artifactId>
          <version>0.1-SNAPSHOT</version>
          <packaging>pom</packaging>
          <name>DiakontEE</name>
          <profiles>
              <profile>
                  <id>dev</id>
                  <activation>
                      <!-- this profile is active by default -->
                      <activeByDefault>true</activeByDefault>
                      <!-- activate if system properties 'env=dev' -->
                      <property>
                          <name>env</name>
                          <value>dev</value>
                      </property>
                  </activation>
                  <properties>
                      <db.url>pgtest.diakont.srl:5433</db.url>
                  </properties>
              </profile>
      
      
              <profile>
                  <id>prod</id>
                  <activation>
                      <!-- activate if system properties 'env=prod' -->
                      <property>
                          <name>env</name>
                          <value>prod</value>
                      </property>
                  </activation>
                  <properties>
                      <db.url>postgres.diakont.srl:5433</db.url>
                  </properties>
              </profile>
      
      
          </profiles>
          <modules>
              <module>DiakontEE-lib</module>
              <module>DiakontEE-web</module>
              <module>DiakontEE-ear</module>
          </modules>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.wildfly.plugins</groupId>
                      <artifactId>wildfly-maven-plugin</artifactId>
                      <version>2.0.1.Final</version>
                      <executions>
                          <execution>
                              <id>deploy-postgresql</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>deploy-artifact</goal>
                              </goals>
                              <configuration>
                                  <groupId>org.postgresql</groupId>
                                  <artifactId>postgresql</artifactId>
                                  <name>postgresql.jar</name>
                              </configuration>
                          </execution>
                          <execution>
                              <id>add-datasource</id>
                              <phase>install</phase>
                              <goals>
                                  <goal>add-resource</goal>
                              </goals>
                              <configuration>
                                  <address>subsystem=datasources</address>
                                  <resources>
                                      <resource>
                                          <address>xa-data-source=java:jboss/datasources/postgresDS</address>
                                          <properties>
                                              <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                                              <jndi-name>java:/jdbc/diakontdb</jndi-name>
                                              <enabled>true</enabled>
                                              <driver-name>postgresql.jar</driver-name>
                                          </properties>
                                          <resources>
                                              <resource>
                                                  <address>
                                                      xa-datasource-properties=DatabaseName
                                                  </address>
                                                  <properties>
                                                      <value>diakont</value>
                                                  </properties>
                                              </resource>
                                              <resource>
                                                  <address>
                                                      xa-datasource-properties=ServerName
                                                  </address>
                                                  <properties>
                                                      <value>${db.url}</value>
                                                  </properties>
                                              </resource>
                                              <resource>
                                                  <address>
                                                      xa-datasource-properties=User
                                                  </address>
                                                  <properties>
                                                      <value>user</value>
                                                  </properties>
                                              </resource>
                                              <resource>
                                                  <address>
                                                      xa-datasource-properties=Password
                                                  </address>
                                                  <properties>
                                                      <value>pass</value>
                                                  </properties>
                                              </resource>
                                          </resources>
                                      </resource>
                                  </resources>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
          <dependencies>
              <dependency>
                  <groupId>org.postgresql</groupId>
                  <artifactId>postgresql</artifactId>
                  <version>42.2.8</version>
              </dependency>
          </dependencies>
      </project>
      
      
      
      
      
      

       

      If I proceed in Netbeans (version 11.1) with "Build with dependencies" and after with "Debug" everything work done in local wildfly connected with Netbeans. Application can see deployed resourced and it can connect to database.

       

      But If I try to deploy the ear (I am developing an enterprise application) in another wildfly, local or remote, the JDBC resource is not deployed and application can not connect with database.

       

      I need help to understand the correct way to deploy application with wildfly-maven-plugin in external and production wildfly servers.

       

      Thanks in advance.

       

      Very kind regards.

       

      Alessio