0 Replies Latest reply on Mar 27, 2017 4:43 PM by hosupc

    Update datasource using maven with cli script

    hosupc

      Hi

       

      I'm using following cli script to create a datasource.

       

      if (outcome != success) of /subsystem=datasources/data-source=CompanyDS:read-resource

           /subsystem=datasources/data-source=CompanyDS:add( \

                jndi-name="java:jboss/datasources/CompanyDS", \

                use-ccm="true", \

                jta="true", \

                enabled="true", \

                driver-name="jtds-1.3.1.jar", \

                driver-class="net.sourceforge.jtds.jdbc.Driver", \

                connection-url="${company.db.connection-url}", \

                user-name="${company.db.username}", \

                password="${company.db.password}")

      end-if

       

      company.db.* properties are defined in external property file. And content of the property file is preloaded in maven before executing cli script.

       

      We'll change database location soon, so I want to update the script to update the datasource somehow. So I added following code before above code to remove datasource first, and re-add it again.

       

      if (outcome == success) of /subsystem=datasources/data-source=CompanyDS:read-resource

           /subsystem=datasources/data-source=CompanyDS:remove()

      end-if

       

      However, this didn't work, because once the datasource is removed, I can't re-add new datasource with same name until server configuration is reloaded.

      We are using maven, so we specify wildly:execute-commands goal in part of maven goals.

       

      ...

      <plugins>

           <plugin>

                <groupId>org.wildfly.plugins</groupId>

                <artifactId>wildfly-maven-plugin</artifactId>

                <version>${version.wildfly.maven.plugin}</version>

       

                <configuration>

                     <execute-commands>

                          <scripts>

                               <script>addDataResources.cli</script>

                          </scripts>

                     </execute-commands>

                </configuration>

       

                <executions>

                     <execution>

                          <id>deploy-jdbc-driver</id>

                          <phase>install</phase>

                          <goals>

                               <goal>deploy-artifact</goal>

                          </goals>

                          <configuration>

                               <groupId>net.sourceforge.jtds</groupId>

                               <artifactId>it's</artifactId>

                               <name>jtds-1.3.1.jar</name>

                          </configuration>

                     </execution>

                </executions>

           </plugin>

      ...

       

      I'd like to how other people using maven update datasource using cli scripts.

       

      Thank you