开发者

Maven war plugin: archiveClasses without archiving resources

There is an archiveClasses option in maven-war-plugin, which packages all the classes in a single .jar, and then creates .war file with that jar in lib/ folder.

I need to do the same, but leave resource files in classes directory, so that they are still a开发者_JAVA技巧ccessible from the classpath but easy to modify.

What is the easiest way to do that?


Maybe you can try to configure your resources folder as a WebResource in the plugin configuration.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <archiveClasses>true</archiveClasses>
        <webResources>
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>WEB-INF/classes</targetPath>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
</plugin>


One line answer : There are no options provided in maven-war-plugin to exclude the resources from the jar created using archiveClasses flag.

The possible and easiest workaround for this problem is to move the files present under src/main/java/resources directory to src/main/java/webapp/WEB-INF/classes directory.


You should just be able to specify where those resources are. It usually looks in src/main/resources for resources, but if you need them in the java source tree you could try:

<resources>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <filtering>true</filtering>
        <includes>
            <include>*.xml</include>                
        </includes>
    </resource>
</resources>


you can do like this to solve the problem:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <warName>${project.war.name}</warName>
        <warSourceExcludes>**/*.class</warSourceExcludes>
        <archiveClasses>true</archiveClasses>
    </configuration>
</plugin>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜