简体   繁体   English

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

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

given the following EAR: 给出以下EAR:

  • my-app.ear 我-app.ear
    • my-ejb .jar my-ejb .jar
    • my-webapp.war 我-webapp.war
    • lib LIB
      • my-lib .jar my-lib .jar

my-ejb need the oracle library to work with oracle spatial in order to construct geometry and to store data. my-ejb需要oracle库与oracle空间一起工作才能构造几何并存储数据。 The module of oracle is correctly loaded by JBOSS 8 (wildfly). 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 META-INF/manifest.mf上添加了oracle驱动程序ojdbc6.jar的依赖项。

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

When I started the application I received ClassNotFoundException oracle.sql.StructDescriptor . 当我启动应用程序时,我收到了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.STRUCT class but the oracle.sql.StructDescriptor is in the same package. 我知道当我从结果集读取数据时,结果集中的对象是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 META-INF/manifest.mf上添加了oracle驱动程序ojdbc6.jar的相同依赖项。

And it works! 它的工作原理!

My question is 我的问题是

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

Santosh has given the correct response, but let me clarify some issues about weblogic vs jboss. Santosh给出了正确的答案,但让我澄清一些关于weblogic vs jboss的问题。

JBOSS and WebLogic have different classoader mechanism. JBOSS和WebLogic具有不同的classoader机制。 Let me clarify: 让我澄清一下:

1. why manifest? 为什么要表现?

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. Oracle Weblogic回复 :WebLogic Server支持可选包,如Java EE 5.0规范,第8.2节“可选包支持”中所述,其中版本控制在可选包版本控制中描述。 Optional packages provide similar functionality to Java EE libraries, allowing you to easily share a single JAR file among multiple applications. 可选包提供与Java EE库类似的功能,允许您在多个应用程序之间轻松共享单个JAR文件。 As with Java EE libraries, optional packages must first be registered with WebLogic Server by deploy the associated JAR file as an optional package. 与Java EE库一样,必须首先通过将关联的JAR文件作为可选包部署,向WebLogic Server注册可选包。 After registering the package, you can deploy Java EE modules that reference the package in their manifest files. 注册包后,您可以在其清单文件中部署引用该包的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库不同,因为可以从任何Java EE模块(EAR,JAR,WAR或RAR存档)或展开的存档目录引用可选包。 Java EE libraries can be referenced only from a valid Enterprise Application. 只能从有效的企业应用程序引用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),而只有Enterprise Applications和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在MANIFEST.MF中为JBoss AS 7生成模块依赖项?

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 ) . 使用新的组织模型,JBOSS 7/8放弃了着名的类加载层次结构,转而使用基于模块化单元( 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; 架构模块的引入(除了即将在JDK中引入的内容,此时由于OSGi等外部项目而流行起来)实际上扩展了用于Java EE应用程序打包的模型。 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. 然后,模块可以是库,类的集合,或者更一般地说是与单个类加载器相关联的资源的集合:因此,与过去不同的是,在一组类的层次结构组织下收集的类加载器,这里的观点完全相反。

see: Class Loading in WildFly 请参阅: WildFly中的类加载

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. 每当创建jar存档时,都会自动创建清单。 There is no specific role related to JBOSS 8 but its general purpose. 没有与JBOSS 8相关的特定角色,但是它的一般用途。 In particular case, if a jar say file1.jar depends on some classes belonging to some other jar say file2.jar file, then those jars should be loaded at the time when the file1.jar is being loaded. 在特殊情况下,如果jar说file1.jar依赖于属于某些其他jar的文件,例如file2.jar文件,则应该在加载file1.jar时加载这些jar。 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. 现在的诀窍是,每当一个jar文件由类加载器加载时,manifest就是告诉类加载器加载这个jar需要的其他jar的方法。 ( Check this link ) This is the reason you code does not work when ojdbc6.jar is missing in the manifest. 检查此链接 )这是清单中缺少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.jar comes bundled with weblogic server and is already loaded when the server starts. 好吧,这是因为在oracle weblogic中, ojdbc6.jar与weblogic服务器捆绑在一起,并且在服务器启动时已经加载。 Please note that even if you have bundled ojdbc6.jar in your application, its not used. 请注意,即使您在应用程序中捆绑了ojdbc6.jar ,也不会使用它。 Here is the relevant documentation for this. 以下是相关文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM