Maven Assembly Plugin
  1. Maven Assembly Plugin
  2. MASSEMBLY-360

When using mulitple Spring dependencies, the files from META-INF (from the Spring jars) overwrite each other in an executable jar-with-dependencies.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2-beta-2
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows XP, Java 5
    • Number of attachments :
      0

      Description

      I'm working on a Java 5 project with maven 2 and I need to deliver an executable jar file. In this project I'm using different Spring dependencies:
      <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>2.5.5</version>
      </dependency>
      <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>2.5.5</version>
      </dependency>

      For maven packaging I'm using the maven-assembly plugin to create an executable jar with dependencies (using the jar-with-dependencies descriptor). Everything works fine, except that Spring's XSD files can't be found. At least: not all of them. The fact is: Every Spring JAR file contains a META-INF directory with files like spring.handlers and spring.schemas which contain list of locations of respectively namespace handlers and schemas. Unfortunately these files aren't merged during packaging so the META_INF of the executable JAR file only contains the last one added.

      This can result in errors like this:

      Example 1: The spring-context-2.5.xsd can't be found:
      WARN org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Ignored XML validation warning org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-2.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

      Example 2: The NamespaceHandler for the spring context namespace can't be located:
      Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/context

      When I manually merge the files, the executable JAR file works fine.
      I hope this problem can be solved.

        Activity

        Hide
        John Casey added a comment -

        @Suresh - Unfortunately that error is bogus. It's something that slipped through in a maven-repository-builder release (used by the assembly plugin), and that component hasn't been re-released since.

        It's not going to affect your build at all; you can safely ignore it.

        Show
        John Casey added a comment - @Suresh - Unfortunately that error is bogus. It's something that slipped through in a maven-repository-builder release (used by the assembly plugin), and that component hasn't been re-released since. It's not going to affect your build at all; you can safely ignore it.
        Hide
        Bernhard Grünewaldt added a comment -

        This Error still appears for me.

        When Using Spring 3.x and using the following Schemas:

        <beans xmlns="http://www.springframework.org/schema/beans"
        	xmlns:aop="http://www.springframework.org/schema/aop"
        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        	xsi:schemaLocation="http://www.springframework.org/schema/beans
        						http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        						http://www.springframework.org/schema/aop
        						http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
        

        I used maven-assembly plugin together with maven 2.x

        I "solved" ist by using the OneJar Plugin.
        http://one-jar.sourceforge.net/

        I tried all the hints about manually merging the context and schema files but nothing helped.
        Is there a Version of the Assembly Plugin which can deal with this issue by itself?

        I really want to go back using the assembly plugin.

        Show
        Bernhard Grünewaldt added a comment - This Error still appears for me. When Using Spring 3.x and using the following Schemas: <beans xmlns= "http: //www.springframework.org/schema/beans" xmlns:aop= "http: //www.springframework.org/schema/aop" xmlns:xsi= "http: //www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http: //www.springframework.org/schema/beans http: //www.springframework.org/schema/beans/spring-beans-3.0.xsd http: //www.springframework.org/schema/aop http: //www.springframework.org/schema/aop/spring-aop-3.0.xsd"> I used maven-assembly plugin together with maven 2.x I "solved" ist by using the OneJar Plugin. http://one-jar.sourceforge.net/ I tried all the hints about manually merging the context and schema files but nothing helped. Is there a Version of the Assembly Plugin which can deal with this issue by itself? I really want to go back using the assembly plugin.
        Hide
        Steven Swor added a comment -

        I still have this issue with Spring 3.1.1-RELEASE and maven-assembly-plugin 2.3 in Maven 3.0.3. I went with Bernhard's solution because it did not require me to add any additional files to my project as a workaround.

        Show
        Steven Swor added a comment - I still have this issue with Spring 3.1.1-RELEASE and maven-assembly-plugin 2.3 in Maven 3.0.3. I went with Bernhard's solution because it did not require me to add any additional files to my project as a workaround.
        Show
        Robert Scholte added a comment - - edited The maven-shade-plugin supports this. http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#Merging_Content_of_Specific_Files_with_AppendingTransformer_and_XmlAppendingTransformer
        Hide
        Viktor Podzigun added a comment -

        This also can be solved by using two other plugins instead:

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>your.main.Class</mainClass>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                </manifest>
            </archive>
        </configuration>
        </plugin>
        
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.1</version>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>false</overWriteSnapshots>
                    <overWriteIfNewer>true</overWriteIfNewer>
                </configuration>
            </execution>
        </executions>
        </plugin>
        

        The idea is that dependencies are not unpacked, but put into the internal lib classpath directory inside the final jar.

        Show
        Viktor Podzigun added a comment - This also can be solved by using two other plugins instead: <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-jar-plugin </artifactId> <version> 2.3.2 </version> <configuration> <archive> <manifest> <mainClass> your.main.Class </mainClass> <addClasspath> true </addClasspath> <classpathPrefix> lib/ </classpathPrefix> </manifest> </archive> </configuration> </plugin> <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-dependency-plugin </artifactId> <version> 2.1 </version> <executions> <execution> <id> copy-dependencies </id> <phase> package </phase> <goals> <goal> copy-dependencies </goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> <overWriteReleases> false </overWriteReleases> <overWriteSnapshots> false </overWriteSnapshots> <overWriteIfNewer> true </overWriteIfNewer> </configuration> </execution> </executions> </plugin> The idea is that dependencies are not unpacked, but put into the internal lib classpath directory inside the final jar.

          People

          • Assignee:
            John Casey
            Reporter:
            Marielle Enderman
          • Votes:
            22 Vote for this issue
            Watchers:
            27 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: