1

一旦我找到解决方案,这个问题就在这里给出答案,我从 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:runpackagepackage

任何需要部署的东西都应该绑定到install阶段。

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

4

2 回答 2

1

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

于 2013-09-24T21:27:36.780 回答
0

这里的解决方案:

conf : jboss as7, maven 3.3.3, mysql java 连接器 5.1.29 28 27 26...,

从 mysql java 连接器 5.1.30 开始,文件 Meta-INF/serivces/java.sql.driver 包含这一行“com.mysql.jdbc.Driver com.mysql.fabric.jdbc.FabricMySQLDriver”,如果我将其更改为“ com.mysql.jdbc.Driver" 数据源已创建并且项目部署正常。

使用 mysql java 连接器 5.1.29 28 27 26 ...,该文件仅包含“com.mysql.jdbc.Driver”,部署工作正常。

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

于 2015-06-21T16:34:08.430 回答