Maven – How exclude files/folder from Maven outputDirectory

maven

I am developing maven project using Spring boot and JSF. According to this example, the managed bean .class files should be put into /src/webapp/WEB-INF/classes directory, to be shown on JFS views. This is achieved by adding outputDirectory tag to pom.xml:

<build>
     <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>  
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring.boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>${maven-compiler-plugin.version}</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.source.version}</source>
                <target>${java.target.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven-war-plugin.version}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

But, I have noticed that except *.class files, there is also stored content of src/main/resources directory: i18n folder, templates folder, *.sql files, application.properties etc….

My question: How to exclude these unnecessary files/folders from /src/webapp/WEB-INF/classes directory?

Best Answer

Just add the file you dont want to the maven exludes.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
   <excludes>
     <exclude>**/src/main/java/myClassesToExclude*.java</exclude>
   </excludes>
 </configuration>
</plugin>
Related Topic