我正在尝试使用 wildfly-maven-plugin 配置WildFly,但我不断收到不同的异常,但我的方法中没有一种有效。
Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:2.0.1.Final:execute-commands (Configure2) on project xp-distribution: Command execution failed for command ' attribute-mapping=[{index=1, to=roles}]}])'. {
"outcome" => "failed",
"failure-description" => {
"WFLYCTL0412: Required services that are not installed:" => ["org.wildfly.data-source.xpDS"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["org.wildfly.security.security-realm.xpDbRealm is missing [org.wildfly.data-source.xpDS]"]
},
"rolled-back" => true
}
我的配置如下:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.1.Final</version>
<executions>
<execution>
<id>start-wildfly1</id>
<goals>
<goal>start</goal>
</goals>
<phase>prepare-package</phase>
</execution>
<execution>
<id>Configure1</id>
<phase>install</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<commands>
<command>module add --name=org.postgresql
--dependencies=javax.api,javax.transaction.api
--resources=${project.build.directory}${file.separator}postgresql-${version.postgres.jdbc}.jar</command>
<command>/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql", driver-class-name="org.postgresql.Driver")</command>
<command>data-source add
--name=xpDS
--driver-name=postgres
--connection-url=jdbc:postgresql://localhost:5432/xp_test
--jndi-name=java:jboss/datasources/xpDS
--use-java-context=true
--user-name=postgres
--password=postgres
--max-pool-size=25
--blocking-timeout-wait-millis=5000
--idle-timeout-minutes=5
--enabled=true</command>
</commands>
</configuration>
</execution>
<execution>
<id>Configure2</id>
<phase>install</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<batch>false</batch>
<scripts>
<script>src/templates/xd1.cli</script>
</scripts>
</configuration>
</execution>
...
我试图在添加数据源和执行脚本之间重新启动wildfly,但错误保持不变。转到target / wildfly-15.0.1.Final / modules我可以看到那里已经添加了PostgreSQL模块。打开standalone.xml,我们可以发现已经添加了xpDS(数据源)。
xd1.cli文件:
###create JDBC-Realm for user validation
/subsystem=elytron/jdbc-realm=xpDbRealm:add( \
principal-query=[ \
{ data-source=xpDS, \
sql="select PASSWORD, SALT, ITERATION_COUNT from T_USER WHERE status = TRUE AND username = ?", \
scram-mapper={algorithm=scram-sha-256,password-index=1, salt-index=2, iteration-count-index=3}}, \
{data-source=xpDS, \
sql="SELECT r.name AS name, 'Roles' as roles from ROLE r INNER JOIN JOIN_UO j ON j.roles = r.u_id INNER JOIN USER u ON j.users = u.um_id WHERE u.username = ?", \
attribute-mapping=[{index=1, to=roles}]}])
###Adding user role decoders
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=roles)
:reload
###Creating a Elytron security domain and adding the created JDBC-Realms
./subsystem=elytron/security-domain=xpDbSD:add( \
realms=[{realm=xpDbRealm, role-decoder=from-roles-attribute}, \
{realm=local, role-mapper=super-user-mapper}], \
default-realm=xpDbRealm, \
permission-mapper=default-permission-mapper, post-realm-principal-transformer=myPostPrincipalTransformer)
:reload
我应该继续使用安装阶段吗?有什么建议可以解决此问题吗?
答案 0 :(得分:1)
重新加载不适用于插件。但是,您可以使用离线CLI,它将启动嵌入式服务器并执行命令。您需要设置jboss-home
属性以使用嵌入式服务器。
这是一个例子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>15.0.1.Final</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.1.Final</version>
<configuration>
<offline>true</offline>
<jboss-home>target/wildfly-15.0.1.Final</jboss-home>
</configuration>
<executions>
<execution>
<id>Configure1</id>
<phase>install</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<commands>
<command>embed-server</command>
<command>module add --name=org.postgresql
--dependencies=javax.api,javax.transaction.api
--resources=${project.build.directory}${file.separator}postgresql-${version.postgres.jdbc}.jar</command>
<command>/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql", driver-class-name="org.postgresql.Driver")</command>
<command>data-source add
--name=xpDS
--driver-name=postgres
--connection-url=jdbc:postgresql://localhost:5432/xp_test
--jndi-name=java:jboss/datasources/xpDS
--use-java-context=true
--user-name=postgres
--password=postgres
--max-pool-size=25
--blocking-timeout-wait-millis=5000
--idle-timeout-minutes=5
--enabled=true</command>
<command>stop-embedded-server</command>
</commands>
</configuration>
</execution>
<execution>
<id>Configure2</id>
<phase>install</phase>
<goals>
<goal>execute-commands</goal>
</goals>
<configuration>
<batch>false</batch>
<scripts>
<script>src/templates/xd1.cli</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
您还需要在CLI脚本中添加embed-server
和stop-embedded-server
。