Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a maven project which creates a war file and this should be deployed to a bundled wildfly server via wildfly:run.
That works so far, but I need to create a datasource before deploying.

I have tried to bind the add-resource goal to different phases like deploy, install or package. None of them worked.

What is wrong?

An idea would be to use the wildfly:start attach an execution to add the datasource and deploy the application, but I don't know how.

<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
    <execution>
        <id>add-datasource</id>
        <phase>deploy</phase>
        <goals>
            <goal>add-resource</goal>
        </goals>
        <configuration>
            <address>subsystem=datasources,data-source=java:jboss/testDB</address>
            <resources>
                <resource>
                    <properties>
                        <jndi-name>java:jboss/testDB</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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
191 views
Welcome To Ask or Share your Answers For Others

1 Answer

My solution is to use the run goal and the beforeDeployment goal:

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <configuration>
        <beforeDeployment>
            <commands>
                <command>data-source add --jndi-name=java:jboss/datasources/OracleDS --name=testDB --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --driver-name=h2 --user-name=sa --password=sa</command>
            </commands>
        </beforeDeployment>
    </configuration>
</plugin>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...