一旦我找到解决方案,这个问题就在这里给出答案,我从 jboss网站上找到了关于 Postgresql 和 H2 数据库的文档,并看到了它是如何通过这个网站手动完成的,但是我似乎找不到太多关于如何使用 jboss-as-maven-plugin 部署 mysql 数据源。
通过他们的 maven 插件向 jboss-as 7 服务器正确注册 mysql 数据源所需的最低配置属性是什么?
我有这个依赖:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
以及 maven 插件的这个配置
<build>
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<execute-commands/>
<executeCommands/>
<properties>
<enable-welcome-root>false</enable-welcome-root>
</properties>
</configuration>
<executions>
...
<!-- deploy the mysql connectorj -->
<execution>
<id>deploy-mysql-driver</id>
<phase>install</phase>
<goals>
<goal>deploy-artifact</goal>
</goals>
<configuration>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<name>mysql.jar</name>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources</address>
<resources>
<resource>
<address>xa-data-source=java:global/datasources/tncDS</address>
<enable-resource>true</enable-resource>
<properties>
<jndi-name>java:jboss/datasources/tncDS</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:mysql://localhost:3306/tnc</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-name>mysql.jar</driver-name>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
...
</plugin>
</plugins>
</build>
运行命令mvn jboss-as:run
会导致此错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.241s
[INFO] Finished at: Tue Sep 24 21:37:28 EST 2013
[INFO] Final Memory: 16M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy-artifact (deploy-mysql-driver) on project ear: Could not execute goal deploy-artifact on null. Reason: I/O Error could not execute operation '{
[ERROR] "address" => [],
[ERROR] "operation" => "read-attribute",
[ERROR] "name" => "launch-type"
[ERROR] }': java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
更新:
我开发了一个插件,可以META-INF/services/java.sql.Driver
在部署之前将所需的文件 ( ) 注入到 jar 中:
<plugin>
<groupId>com.thenaglecode</groupId>
<artifactId>mysql-jdbc-compliance-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</configuration>
<executions>
<execution>
<goals>
<goal>modify-connector</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
但是我仍然收到could not connect to remote
消息。我知道运行命令应该启动服务器,因此是否有我遗漏或执行错误顺序的步骤。
更新 2:在对 jboss-as 插件网站
进行一些摆弄和阅读之后,我意识到目标也调用了阶段。当我尝试运行绑定到阶段的任何部署目标时,我主要收到此错误。jboss-as:run
package
package
任何需要部署的东西都应该绑定到install
阶段。
我现在收到关于我的持久性单元不存在的单独错误