oracle 为什么我们必须声明对 JBOSS 8 (wildfly) 清单的依赖?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25303127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:27:43  来源:igfitidea点击:

Why we have to declare dependencies on manifest of JBOSS 8 (wildfly)?

javaoraclejbosswildflymanifest.mf

提问by giusy

given the following EAR:

鉴于以下 EAR:

  • my-app.ear
    • my-ejb.jar
    • my-webapp.war
    • lib
      • my-lib.jar
  • 我的应用程序.ear
    • 我的 ejb.jar
    • 我的 webapp.war
      • 我的库.jar

my-ejb need the oracle library to work with oracle spatial in order to construct geometry and to store data. The module of oracle is correctly loaded by JBOSS 8 (wildfly).

my-ejb 需要 oracle 库与 oracle 空间一起工作,以便构建几何图形和存储数据。JBOSS 8(wildfly)正确加载了oracle的模块。

When I started the application I received ClassNotFoundException oracle.sql.STRUCT.

当我开始申请时,我收到了ClassNotFoundException oracle.sql.STRUCT.

OK I added the dependency of oracle driver ojdbc6.jar on my-ejb META-INF/manifest.mf.

好的,我在 my-ejb 上添加了 oracle 驱动程序 ojdbc6.jar 的依赖项META-INF/manifest.mf

Class-Path: ojdbc6.jar
Dependencies: oracle.sql 

When I started the application I received ClassNotFoundException oracle.sql.StructDescriptor. I know that when I read data to and from a resultset, the object coming out of the resultset is an instance of a oracle.sql.STRUCTclass but the oracle.sql.StructDescriptoris in the same package.

当我开始申请时,我收到了ClassNotFoundException oracle.sql.StructDescriptor. 我知道当我从结果集读取数据时,从结果集出来的对象是一个oracle.sql.STRUCT类的实例,但oracle.sql.StructDescriptor它在同一个包中。

OK I added the same dependency of oracle driver ojdbc6.jar on my-lib META-INF/manifest.mf.

好的,我在 my-lib 上添加了与 oracle 驱动程序 ojdbc6.jar 相同的依赖项META-INF/manifest.mf

And it works!

它有效!

My question is

我的问题是

  • which is the role of manifets on JBOSS 8?
  • why on oracle weblogic I do NOT need to add these dependencies on manifest.mf?
  • 清单在 JBOSS 8 上的作用是什么?
  • 为什么在 oracle weblogic 上我不需要在 manifest.mf 上添加这些依赖项?

回答by venergiac

Santosh has given the correct response, but let me clarify some issues about weblogic vs jboss.

Santosh 给出了正确的回应,但让我澄清一些关于 weblogic 与 jboss 的问题。

JBOSS and WebLogic have different classoader mechanism. Let me clarify:

JBOSS 和 WebLogic 具有不同的类加载器机制。让我澄清一下:

1. why manifest?

1.为什么要显化?

Java-Oracle reply: You may need to reference classes in other JAR files from within a JAR file.

Java-Oracle 回复:您可能需要从 JAR 文件中引用其他 JAR 文件中的类。

2. why manifest on EAR/WAR application?

2. 为什么在 EAR/WAR 应用程序中显示?

Oracle Weblogic reply: WebLogic Server supports optional packages as described in the Java EE 5.0 Specification, Section 8.2 Optional Package Support, with versioning described in Optional Package Versioning. Optional packages provide similar functionality to Java EE libraries, allowing you to easily share a single JAR file among multiple applications. As with Java EE libraries, optional packages must first be registered with WebLogic Server by deploy the associated JAR file as an optional package. After registering the package, you can deploy Java EE modules that reference the package in their manifest files.

Oracle Weblogic 回复:WebLogic Server 支持可选包,如 Java EE 5.0 规范第 8.2 节可选包支持中所述,版本控制在可选包版本控制中描述。可选包提供与 Java EE 库类似的功能,允许您在多个应用程序之间轻松共享单个 JAR 文件。与 Java EE 库一样,必须首先通过将关联的 JAR 文件部署为可选包来向 WebLogic Server 注册可选包。注册包后,您可以部署在其清单文件中引用包的 Java EE 模块。

Optional packages differ from Java EE libraries because optional packages can be referenced from any Java EE module (EAR, JAR, WAR, or RAR archive) or exploded archive directory. Java EE libraries can be referenced only from a valid Enterprise Application.

可选包不同于 Java EE 库,因为可选包可以从任何 Java EE 模块(EAR、JAR、WAR 或 RAR 存档)或展开的存档目录中引用。Java EE 库只能从有效的企业应用程序中引用。

[...]

[...]

Any Java EE application or module can reference an optional package (using META-INF/MANIFEST.MF), whereas only Enterprise Applications and Web applications can reference a shared Java EE library (using weblogic-application.xml or weblogic.xml)

任何 Java EE 应用程序或模块都可以引用可选包(使用 META-INF/MANIFEST.MF),而只有企业应用程序和 Web 应用程序可以引用共享的 Java EE 库(使用 weblogic-application.xml 或 weblogic.xml)

3. then why we have to no declare java-ee-api.jar, jsf, jsp, ...

3. 那为什么我们不用声明java-ee-api.jar, jsf, jsp, ...

Jboss reply: The following table lists the modules that are automatically added to deployments as dependencies and the conditions that trigger the dependency.

Jboss 回复:下表列出了自动添加到部署中作为依赖项的模块以及触发依赖项的条件。

Implicit_Module_Dependencies

Implicit_Module_Dependencies

4. are not all modules loaded by JBOSS?

4.不是所有的模块都被JBOSS加载了吗?

Jboss reply: this chapter will talk about how applications packaged as jars can declare that they depend on one or more modules:

Jboss 回复:本章将讨论打包为jar 的应用程序如何声明它们依赖于一个或多个模块:

Dependencies: oracle.sql, another.module.with.version:1.0

Manifest module information

清单模块信息

4.1 alternatively define the jboss-deployment-structure.xml

4.1 交替定义 jboss-deployment-structure.xml

<jboss-deployment-structure>

   <deployment>

      <dependencies>
         <module name="oracle.sql" export="TRUE" />
      </dependencies>

   </deployment>

</jboss-deployment-structure>

Add anExplicit Module Dependency to a Deployment

向部署添加显式模块依赖项

4.2 with maven

4.2 与 Maven

<plugins>

   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
         <archive>
            <manifestEntries>
               <Dependencies>org.javassist, org.apache.velocity</Dependencies>
            </manifestEntries>
         </archive>
      </configuration>
   </plugin> 

</plugins>

see: Generate MANIFESTMF entries using Maven

请参阅:使用 Maven 生成 MANIFESTMF 条目

see: How do you generate module dependencies in MANIFEST.MF for JBoss AS 7 with maven?

请参阅:如何使用 maven 在 JBoss AS 7 的 MANIFEST.MF 中生成模块依赖项?

7. why we didn't get this important information before?

7.为什么我们之前没有得到这个重要信息?

With the new organizational model JBOSS 7/8 abandons the famous classloading hierarchy to switch to a simpler model based on the use of modular units (JBoss Modules Project) . The introduction of the architecture modules (in addition to the forthcoming introduction in the JDK, much in vogue at this time thanks to external projects such as OSGi) actually extends the model in use for the packaging of Java EE applications; a module can then be a library, a collection of classes, or more generally a collection of resources associated with a single classloader: therefore, unlike the past, where the classloader that was collected under a hierarchical organization of a set of classes, the point here of view is exactly reversed.

通过新的组织模型,JBOSS 7/8 放弃了著名的类加载层次结构,转而使用基于模块化单元(JBoss 模块项目)的更简单的模型。架构模块的引入(除了即将在 JDK 中引入,由于 OSGi 等外部项目而在此时非常流行)实际上扩展了用于打包 Java EE 应用程序的模型;一个模块可以是一个库、一个类的集合,或者更一般地说是与单个类加载器相关联的资源集合:因此,与过去不同,在过去,类加载器是在一组类的分层组织下收集的,重点是这里的观点正好相反。

see: Class Loading in WildFly

请参阅:WildFly 中的类加载

回答by Santosh

To answer your question:

回答你的问题:

  • which is the role of manifets on JBOSS 8?
  • 清单在 JBOSS 8 上的作用是什么?

Manifests are automatically created whenever a jar archive is created. There is no specific role related to JBOSS 8 but its general purpose. In particular case, if a jar say file1.jardepends on some classes belonging to some other jar say file2.jarfile, then those jars should be loaded at the time when the file1.jaris being loaded. Now the trick is, whenever a jar file is loaded by a classloader, manifest is a way to tell classloader to load other jars which this jar needs. (Check this link) This is the reason you code does not work when ojdbc6.jaris missing in the manifest.

每当创建 jar 存档时,就会自动创建清单。没有与 JBOSS 8 相关的特定角色,而是它的通用目的。在特定情况下,如果 jar 文件file1.jar依赖于属于其他 jar文件的某些类,例如file2.jar文件,那么应该在加载file1.jar时加载这些 jar 。现在的技巧是,每当类加载器加载 jar 文件时,清单是一种告诉类加载器加载该 jar 需要的其他 jar 的方法。(检查此链接)这就是当清单中缺少ojdbc6.jar时您的代码不起作用的原因。

  • why on oracle weblogic I do NOT need to add these dependencies on manifest.mf?
  • 为什么在 oracle weblogic 上我不需要在 manifest.mf 上添加这些依赖项?

Well, this is because in oracle weblogic, the ojdbc6.jarcomes bundled with weblogic server and is already loaded when the server starts. Please note that even if you have bundled ojdbc6.jarin your application, its not used. Here is the relevant documentationfor this.

嗯,这是因为在oracle weblogic 中,ojdbc6.jar是和weblogic server 绑定的,在server 启动的时候就已经加载好了。请注意,即使您在应用程序中捆绑了ojdbc6.jar,它也不会被使用。这是相关的文档