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

2

5

given the following EAR:

  • my-app.ear
    • my-ejb.jar
    • my-webapp.war
    • lib
      • my-lib.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).

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

OK I added the dependency of oracle driver ojdbc6.jar on my-ejb 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.STRUCT class but the oracle.sql.StructDescriptor is in the same package.

OK I added the same dependency of oracle driver ojdbc6.jar on my-lib 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?
Raguelragweed answered 14/8, 2014 at 8:11 Comment(0)
R
8

To answer your question:

  • which is the role of manifets on 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.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. 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.jar is missing in the manifest.

  • why on oracle weblogic I do NOT need to add these dependencies on 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. Please note that even if you have bundled ojdbc6.jar in your application, its not used. Here is the relevant documentation for this.

Reefer answered 14/8, 2014 at 9:46 Comment(0)
C
15

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

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

1. why manifest?

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

2. why manifest on EAR/WAR application?

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.

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.

[...]

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)

3. then why we have to no declare 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.

Implicit_Module_Dependencies

4. are not all modules loaded by JBOSS?

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

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

Manifest module information

4.1 alternatively define the 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

<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

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

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

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.

see: Class Loading in WildFly

Coptic answered 15/8, 2014 at 9:44 Comment(0)
R
8

To answer your question:

  • which is the role of manifets on 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.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. 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.jar is missing in the manifest.

  • why on oracle weblogic I do NOT need to add these dependencies on 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. Please note that even if you have bundled ojdbc6.jar in your application, its not used. Here is the relevant documentation for this.

Reefer answered 14/8, 2014 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.