创建数据源并部署应用程序 [英] Create datasource and deploy application
问题描述
我有一个maven项目,该项目创建一个war文件,应该通过wildfly:run
将该文件部署到捆绑的wildfly服务器中.
到目前为止,该方法仍然有效,但是我需要在部署之前创建一个数据源.
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.
怎么了?
一个想法是使用wildfly:start
附加执行以添加数据源并部署应用程序,但是我不知道如何.
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>
推荐答案
我的解决方案是使用运行目标和beforeDeployment目标:
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>
这篇关于创建数据源并部署应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!