【问题标题】:Exclude resource package from maven dependency (webjars)从 maven 依赖项(webjars)中排除资源包
【发布时间】:2016-04-26 14:44:31
【问题描述】:

我的 pom 中有依赖项:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>extjs</artifactId>
    <version>6.0.0</version>
</dependency>

将我的项目构建成战争后,我收到了一个超过 200MB 的包。 是否有可能排除包

/webjars/extjs/6.0.0/build/examples/

来自这个依赖?我该怎么做?

我尝试过使用 shade 插件,但它不起作用,也在 war 插件配置中:

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

没用。

【问题讨论】:

    标签: java maven extjs dependencies war


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        感谢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>
        

        【讨论】:

          猜你喜欢
          • 2016-06-20
          • 2015-02-19
          • 2012-02-25
          • 2016-06-11
          • 1970-01-01
          • 1970-01-01
          • 2020-02-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多