0

I want to build my spring boot app, but I have to transfer the files around a lot into different servers. But my "libs" folder inside my "jar" file, is too big now. It's 100MB++.

What I want is to periodically update my webapp, that is like 1MB or something, and keep a copy of my 100MB "libs" folder on the output directory at different servers. Only updating the libs rarely.

The following POM file makes a 100MB JAR... and then makes 100MB "libs" folder. Then zips the two together. But I don't know how to make 100MBJAR smaller (what springboot libs are most important to be compiled together?). I think I need an <include> tag or something.

But I haven't found the right way to configure "spring boot maven plugin" so that it only includes the most essential files from SpringBoot & TomCat Embedded, but keeps most of the other libraries outside in a different folder.

(bottom of my) POM.xml

<build>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>node_modules/**</exclude>
                    <exclude>bower_components/**</exclude>
                    <exclude>node/**</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>${project.build.directory}/generated-resources</directory>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                    </configuration>
                </plugin>   
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.0</version>                    
                <configuration>
                   <projectNameTemplate>[groupId].[artifactId]</projectNameTemplate>
                </configuration>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                          <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                          <outputDirectory>${project.build.directory}/${project.build.finalName}.lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>                   
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-jar-plugin</artifactId>
                  <configuration>
                    <archive>
                      <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
                        <mainClass>${fully.qualified.main.class}</mainClass>
                      </manifest>
                    </archive>
                  </configuration>
              </plugin>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-antrun-plugin</artifactId>
                  <executions>
                    <execution>
                      <id>antrun-archive</id>
                      <phase>package</phase>
                      <goals>
                        <goal>run</goal>
                      </goals>
                      <configuration>
                        <target>
                          <property name="final.name" value="${project.build.directory}/${project.build.finalName}"/>
                          <property name="archive.includes" value="${project.build.finalName}.${project.packaging} ${project.build.finalName}.lib/*"/>
                          <property name="tar.destfile" value="${final.name}.tar"/>
                          <!-- <zip basedir="${project.build.directory}" destfile="${final.name}.zip" includes="${archive.includes}" /> -->
                          <tar basedir="${project.build.directory}" destfile="${tar.destfile}" includes="${archive.includes}" />
                          <gzip src="${tar.destfile}" destfile="${tar.destfile}.gz" />
                          <!-- <bzip2 src="${tar.destfile}" destfile="${tar.destfile}.bz2" /> -->
                        </target>
                      </configuration>
                    </execution>
                  </executions>
              </plugin>
        </plugins>
    </build>
Dexter
  • 6,170
  • 18
  • 74
  • 101
  • See https://github.com/dsyer/spring-boot-thin-launcher – M. Deinum Apr 24 '17 at 05:59
  • I'd rather look for using `rsync` and/or creating binary delta files because you're fighting against the fundamental idea of the Spring Boot -- having a single self-sufficient JAR file. Another option is to use standalone Tomcat server with a Spring MVC application and mark some dependencies as `runtime` to tell the Maven to not include them in the JAR file. – Slava Semushin Apr 24 '17 at 10:41

1 Answers1

0

Added "excludeGroupIds" to spring-boot-maven-plugin and comma-separated list of groupIDs, and it worked. Removed it from the core jar.

Remember this is NON-standard, and shouldn't be done due to the fact that it defeats purpose of SpringBoot (So might as well use Java Spark2 Framework or something more modern, then configure Tomcat separately), or just send the 100MB package over. But this was necessary here because of slow connections.

Dexter
  • 6,170
  • 18
  • 74
  • 101