Maven war plugin: archiveClasses without archiving resources

The maven-war-plugin has an option archiveClassesthat packs all classes into a single .jar, and then creates a .war file with this bank in the lib / folder.

I need to do the same, but leave the resource files in the class directory so that they are still accessible from the class path, but easily changed.

What is the easiest way to do this?

+5
source share
4 answers

Perhaps you can try to configure the resource folder as a WebResource in the plugins.

<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>
+4
source

: maven-war-plugin , , archiveClasses.

, src/main/java/resources, src/main/java/webapp/WEB-INF/classes.

+2

You should simply indicate where these resources are. It usually looks in src / main / resources resources, but if you need them in the java source tree, you can try:

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

You can do 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
source

All Articles