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.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
migu
  • 1,371
  • 1
  • 14
  • 23

2 Answers2

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.

Mike Minicki
  • 8,216
  • 11
  • 39
  • 43
  • '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? – migu Jul 16 '11 at 19:32
  • 2
    @migu - 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. – Mike Minicki Jul 17 '11 at 09:38
  • 2
    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. – migu May 09 '12 at 13:23
  • 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. – migu Jun 04 '13 at 14:25
  • 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. – gkephorus Mar 27 '16 at 18:23
  • 1
    In any case, this works well for one dependency, but how can i add more dependencies? i tried several things and nothing worked @Mike-Minicki – Marc Guillem Dec 13 '21 at 15:07
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

Jérome Pieret
  • 228
  • 2
  • 10
  • 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. – migu Dec 05 '13 at 14:37