简体   繁体   中英

Why spring boot modify jar in source resources?

My spring boot construction like this:

/src/main/resources/
  +- /lib
     +- logback-classic-1.1.9-source.jar
     +- logback-classic-1.1.9.jar

and the pom I used :

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    <resources>  
       <resource>  
           <directory>src/main/resources/</directory>  
           <filtering>true</filtering>  
           <includes>  
               <include>**/*</include>  
           </includes>  
       </resource>    
   </resources> 
</build>

and I put the spring boot project packaging into war file. When I use mvn clean install to get the war file, what is shocking at me is the logback-classic-1.1.9-source.jar and logback-classic-1.1.9.jar in the war has been changed!! The two jars in the source lib file are all 248KB but, in war file, they changed to 418KB and 420KB!! The jar is broken, 7-zip can not unzip the jar!

I don't know why. Could any one help me? thank you!

also I can use

<excludes>
    <exclude>**/*.jar</exclude> 
</excludes>

to exclude move jar into the war, but I just want to know what is wrong with my code let the spring boot change my jar in resources.

I also try the spring project, in that case, all things are OK! My jar didn't change in the war file.

You have the libs underneath the src/main/resources path and they are copied with filtering set to true. So in the process of copying the resources, they will be modified if they contain String in the form ${...} .

The first solution would be to not include the jars as resources. Do you reall need the source jar in your final artefact? If not, remove this lib folder and add a dependency to the logback-classic jar:

<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.1.9</version>
</dependency>

The latest version by the way is 1.2.3. Using this will put the logback-jar where it belongs when you build the project with mvn package and is the normal way of adding dependent libraries.

If you really want to keep this in the resources, you should exclude the lib directory from the filtering and copy it unfiltered:

<resources>
    <resource>
        <directory>src/main/resources/</directory>
        <filtering>true</filtering>
        <includes>
            <include>**/*</include>
        </includes>
        <excludes>
            <exclude>lib</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources/lib</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*</include>
        </includes>
    </resource>
</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM