简体   繁体   中英

Exclude resource package from maven dependency (webjars)

I have dependency in my pom:

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

After building my project into war, I received a pack that has over 200MB. Is there a possibility to exclude package

/webjars/extjs/6.0.0/build/examples/

from this dependency? How can I do that?

I've tried to use shade plugin, but it doesn't work, also in war plugin config:

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

doesn't work.

Please have a look at this page. It talks about how to shrink webjar by excluding unnecessary content.

You could use the maven-assembly-plugin and use the exclude within the dependencySet . The following question how to exclude a resource file in a maven assembly gives some more background.

Thanks to Dark Knight i found the solution that works for me:

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

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