jar file gets corrupted while building with maven

前端 未结 5 1105
粉色の甜心
粉色の甜心 2020-12-15 16:07

while building a war file i am copying a set of jars from a location to a folder inside the war. While the files do get copied , however i think they get corrupted because t

相关标签:
5条回答
  • 2020-12-15 16:47

    I had a similar error when I've added

    <copy ...>
    <fileset ... />
    <filterchain>
        <tokenfilter>
             <replacestring from="..." to="..." />
        </tokenfilter>
    </filterchain>
    </copy>
    

    to my copy task in ANT. It corrupted the jar files when copying them. I've solved this by applying the filter ONLY on the targeted text files and not on jar files.

    0 讨论(0)
  • 2020-12-15 16:53

    Also, you can continue benefit to use maven filtering without corrupting jars inside.

    We choose to exclude jar from filtered extensions.

    In th pluginManagement section of the parent pom we put this configuration

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <encoding>${project.build.sourceEncoding}</encoding>
          <nonFilteredFileExtensions>
            <nonFilteredFileExtension>jar</nonFilteredFileExtension>
            <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
            <nonFilteredFileExtension>swf</nonFilteredFileExtension>
            <nonFilteredFileExtension>zip</nonFilteredFileExtension>
            <nonFilteredFileExtension>bz2</nonFilteredFileExtension>
            <nonFilteredFileExtension>gz</nonFilteredFileExtension>
            <nonFilteredFileExtension>acp</nonFilteredFileExtension>
            <nonFilteredFileExtension>bin</nonFilteredFileExtension>
            <nonFilteredFileExtension>odt</nonFilteredFileExtension>
            <nonFilteredFileExtension>doc</nonFilteredFileExtension>
            <nonFilteredFileExtension>xls</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
        </configuration>
      </plugin>
    

    Note we added jar extensions as well as default maven excluded filetypes (its a zip after all).

    Besides avoiding corruption of the archive it also speeds up the process as it does not have to filter large files.

    0 讨论(0)
  • 2020-12-15 16:54

    Just as addition to the other answers, the other option is to enable the filtering only for the resources that require filtering:

    <build>
    ...
            <resources>
                <resource>
                    <filtering>true</filtering>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>core.properties</include>
                    </includes>
                </resource>
                <resource>
                    <filtering>false</filtering>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>pdf/color_profile/sRGB.icc</include>
                    </includes>
                </resource>
            </resources>
    </build>
    
    0 讨论(0)
  • 2020-12-15 17:01

    Remove <filtering>true</filtering>, it corrupts the jar files.

    0 讨论(0)
  • 2020-12-15 17:04

    Try Maven Assembly Plugin. It's my favourite plugin to add custom resources to a *.war file. See also Pre-defined Descriptor Files.

    0 讨论(0)
提交回复
热议问题