从maven依赖项中排除资源包(webjars)

时间:2016-04-26 05:36:41

标签: java maven extjs dependencies war

我对我的pom依赖:

/webjars/extjs/6.0.0/build/examples/

在我的项目进入战争之后,我收到了一个超过200MB的包。 是否有可能排除包

<configuration>
   <packagingExcludes>
         /webjars/extjs/${extjs.version}/build/examples/
   </packagingExcludes>
</configuration>

来自这种依赖?我怎么能这样做?

我曾尝试使用shade插件,但它不起作用,也适用于war插件配置:

{{1}}

不起作用。

3 个答案:

答案 0 :(得分:0)

请查看this页面。它讨论了如何通过排除不必要的内容来缩小webjar。

答案 1 :(得分:0)

您可以使用maven-assembly-plugin并使用dependencySet中的exclude。以下问题how to exclude a resource file in a maven assembly提供了更多背景信息。

答案 2 :(得分:0)

感谢Dark Knight我找到了适合我的解决方案:

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>extjs</artifactId>
        <version>${extjs.version}</version>
        <scope>provided</scope>
    </dependency>
...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    </manifest>
                </archive>
                <webResources>
                    <resource>
                        <directory>${project.build.directory}\extjs\META-INF\resources</directory>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack-jar</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.webjars</groupId>
                                <artifactId>extjs</artifactId>
                                <version>${extjs.version}</version>
                                <type>jar</type>
                                <destFileName>extjs-dependency</destFileName>
                                <includes>
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/*.*,
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/classic/**/*.*,
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/packages/**/*.*
                                </includes>
                                <outputDirectory>
                                    ${project.build.directory}/extjs
                                </outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>