gpt4 book ai didi

java - 为什么我们在 JBoss AS 7 中定义驱动程序模块时要指定依赖项?

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:35 25 4
gpt4 key购买 nike

这就是 official JBoss documentation 中驱动程序的定义方式

<module xmlns="urn:jboss:module:1.0" name="com.mysql">  
<resources>
<resource-root path="mysql-connector-java-5.1.21.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module

我不明白为什么我们应该定义依赖标签?它负责什么?当然,我们应该定义一个驱动程序的路径,这很清楚。但是<dependencies>使我困惑。谁能给我解释一下吗?

最佳答案

它在您提供的文档链接中说明

Finally, you define any dependencies you might have. In this case, as the case with all JDBC data sources, we would be dependent on the Java JDBC API's, which in this case in defined in another module called javax.api, which you can find under modules/javax/api/main as you would expect.

您可以查看突出显示的目录,您会发现另一个 module.xml 。这是命名模块 "javax.api" 的模块定义。正如您将模块定义为 "com.mysql" 一样,如果系统中的任何其他模块需要您的模块,它也会定义 <dependencies>元素与您的模块名称。

模块简单地定义为

A Module is a logical grouping of classes used for class loading and dependency management...

A module dependency is a declaration that one module requires the classes of another module in order to function. Modules can declare dependencies on any number of other modules. When the application server loads a module, the modular class loader parses the dependencies of that module and adds the classes from each dependency to its class path.

如果您熟悉 Maven,就会发现这是一样的事情。一个依赖项可能依赖于其他依赖项。在 pom.xml工件将定义其依赖项。如果您依赖于该工件,那么您还需要它的依赖项。

进一步阅读:

关于java - 为什么我们在 JBoss AS 7 中定义驱动程序模块时要指定依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com