如何使用jboss-as-maven-plugin部署mysql数据源

时间:2013-09-24 11:41:01

标签: mysql maven jboss jboss7.x

这个问题在这里给出一个答案,一旦我找到解决方案,我已经从jboss website找到了关于Postgresql和H2数据库的文档,并看到了如何通过这个website手动完成它但是,我似乎无法找到有关如何使用jboss-as-maven-plugin部署mysql数据源的更多信息。

使用jboss-as 7服务器通过maven插件正确注册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条消息。是否有一个我缺少或按错误顺序执行的步骤,因为我知道run命令应该启动服务器。

更新2:
经过一些摆弄和阅读jboss-as插件website之后,我意识到jboss-as:run目标也会调用package阶段。当我尝试运行绑定到package阶段的任何部署目标时,我主要收到此错误。

任何需要部署的内容都应绑定到install阶段。

我现在收到关于我的持久性单元不存在的单独错误

2 个答案:

答案 0 :(得分:1)

问题是MySQL驱动程序不符合JDBC 4。您需要使用完全限定的JDBC驱动程序类名称​​或META-INF/services/java.sql.Driver文件添加到JAR,并将其作为模块安装。有关详细信息,请参阅https://community.jboss.org/wiki/DataSourceConfigurationInAS7

答案 1 :(得分:0)

解决方案:

conf:jboss as7,maven 3.3.3,mysql java connector 5.1.29 28 27 26 ...,

从mysql java连接器5.1.30开始,文件Meta-INF / serivces / java.sql.driver包含此行&#34; com.mysql.jdbc.Driver 如果我把它改成&#34; com.mysql.jdbc.Driver&#34;创建数据源并正确部署项目。

使用mysql java连接器5.1.29 28 27 26 ...,该文件只包含&#34; com.mysql.jdbc.Driver&#34;,部署工作正常。

在这里查看我的pom.xml https://github.com/anouarattn/GestionAbsence