How do you generate module dependencies in MANIFEST.MF for JBoss AS 7 with maven?
Asked Answered
H

2

30

In JBoss AS 7, a Web application that depends on libraries contained in the AS, must declare those dependencies in META-INF/MANIFEST.MF like this:

Dependencies: <package-name>

Example:

Dependencies: org.slf4j

(This is comparable to Import-Package: for OSGi.) Further information can be found in the articles about migration from older versions, class loading and implicit module dependencies for deployments

The project is built with Maven. All dependencies included in the AS are declared with scope 'provided'.

Now the question

Is there a simple way to create this list of dependencies automatically with Maven?

Only dependencies with declared scope 'provided' should be included, because all others are already included in the WAR.

Hyperion answered 14/7, 2011 at 8:55 Comment(0)
C
28

Those dependencies are declared by names which maven artifacts don't have any mappings to. You probably could keep groupId in sync with jboss module names but I'm not sure if it's a good idea. And I still can't think of any automated solution.

But there is a place where you can manage the configuration by hand, as described in one of the sources you provided in your question:

   <build>
       ...
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-war-plugin</artifactId>
           <configuration>
              <archive>
                 <manifestEntries>
                    <Dependencies>org.slf4j</Dependencies>
                 </manifestEntries>  
              </archive>
           </configuration>
         </plugin>   
       </plugins>
    </build>

I hope someone comes up with a plugin to make it less cumbersome.

Chancre answered 16/7, 2011 at 8:54 Comment(6)
'org.slf4j' is the artifact's group id, so Maven knows it already. However, this group id is used by several artifact's. How does JBoss know which jar is meant?Hyperion
@Hyperion - Take a look into modules/org/slf4j/main folder in jboss root directory (as this is imported by this org.slf4j dependency). And specifically look into module.xml which acts as its descriptor. As you see, it's only a coincidence that maven group and this module uses the same name.Chancre
This seems to be the only solution currently available. The downside of the new JBoss module system is that we have to maintain two overlapping sets of dependencies in the POM, and that we have to lookup the modules we can use by hand.Hyperion
This is what I understood: The upside should be the separation of modules into separate class loader scopes. This makes it possible to use different jar versions in the same AS.Hyperion
Maven could define a scope that mentions information about what the JBoss-module-name would be. That way developers could reference that scope to find this so badly needed information.Tomkins
In any case, this works well for one dependency, but how can i add more dependencies? i tried several things and nothing worked @Mike-MinickiJorge
L
1

This code add automaticaly all of your compile depedencies in your MANIFEST.MF

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.4</version>
   <configuration>
      <archive>
         <manifest>
            <addClasspath>true</addClasspath>
         </manifest>
      </archive>
   </configuration>
</plugin>

more info here : http://maven.apache.org/plugins/maven-war-plugin/examples/war-manifest-guide.html

Labellum answered 8/11, 2013 at 19:57 Comment(1)
As Michał Minicki already pointed out, it's only a coincidence that maven groups and some modules have the same name. Therefore, it won't help to add the classpath because JBoss AS expects module names.Hyperion

© 2022 - 2024 — McMap. All rights reserved.