1

Is it possible to add a datasource or jdbc-driver by executing the wildfly:add-resource goal. I only get a warning when executing the goal which says "No resources were provided".

I used the "Adding Datasource" example from the projects documentation. (https://docs.jboss.org/wildfly/plugins/maven/latest/examples/add-resource-example.html)

Executing the package lifecycle adds the datasource to the standalone.xml but executing mvn wildfly:add-resource exits with the No resource were provided message.

Thanks for helping!

I only use the maven-wildfly-plugin for local development. So i want to execute a single goal to configure my local application server.

Here a brief summary of my pom.xml.

<?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>

  ...

  <packaging>war</packaging>

  <name>${project.artifactId}</name>

  <properties>

    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.source>11</maven.compiler.source>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  </properties>

  <build>

    <plugins>

      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>4.1.0.Beta1</version>
        <configuration>
          <id>standalone</id>
          <hostname>localhost</hostname>
          <port>9990</port>
          <username>admin</username>
          <password>admin</password>
          <startupTimeout>120</startupTimeout>
        </configuration>
        <executions>

          <execution>
            <id>add-datasource</id>
            <phase>package</phase>
            <goals>
              <goal>add-resource</goal>
            </goals>
            <configuration>
              <address>subsystem=datasources,data-source=java:jboss/myDs</address>
              <resources>
                <resource>
                  <properties>
                    <jndi-name>java:jboss/myDs</jndi-name>
                    <enabled>true</enabled>
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                    <driver-class>org.h2.Driver</driver-class>
                    <driver-name>h2</driver-name>
                    <user-name>sa</user-name>
                    <password>sa</password>
                  </properties>
                </resource>
              </resources>
            </configuration>
          </execution>

        </executions>

      </plugin>

    </plugins>

  </build>

</project>
schth
  • 11
  • 2
  • Could you paste your pom.xml also in the question? And can explain more about what steps are you performing and at what step you are getting problem – Vaibhav Sharma May 16 '23 at 10:52
  • What version of the plugin are you using? 4.1.0.Final is the latest, https://docs.wildfly.org/wildfly-maven-plugin/. It does require Java 11 as a minimum, but should work with any version of WildFly. – James R. Perkins May 16 '23 at 16:08
  • @VaibhavSharma thanks for helping. I have updated my question with the pom.xml and more details about my problem. – schth May 17 '23 at 06:50

1 Answers1

1

If you want to execute the add-resource goal from the command line you need to move your configuration. You've got the configuration defined in the execution, it needs to be moved up to the main configuration level.

Note below I'm changing the version to 4.1.0.Final.

<?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>org.wildfly.example</groupId>
  <artifactId>example-war</artifactId>
  <packaging>war</packaging>
  <name>${project.artifactId}</name>
  <properties>
    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.source>11</maven.compiler.source>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>4.1.0.Final</version>
        <configuration>
          <id>standalone</id>
          <hostname>localhost</hostname>
          <port>9990</port>
          <username>admin</username>
          <password>admin</password>
          <startupTimeout>120</startupTimeout>
          <!-- JDBC resource configuration -->
          <address>subsystem=datasources,data-source=java:jboss/myDs</address>
          <resources>
            <resource>
              <properties>
                <jndi-name>java:jboss/myDs</jndi-name>
                <enabled>true</enabled>
                <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                <driver-class>org.h2.Driver</driver-class>
                <driver-name>h2</driver-name>
                <user-name>sa</user-name>
                <password>sa</password>
              </properties>
            </resource>
          </resources>
        </configuration>
        <executions>
          <execution>
            <id>add-datasource</id>
            <phase>package</phase>
            <goals>
              <goal>add-resource</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
James R. Perkins
  • 16,800
  • 44
  • 60