Question

I'm trying to add maven filtering to a project i'm working on, but after I build the project with filtering on, all of the injected beans are null. Here is the addition to the pom:

<build>
        ...
        <filters>
            <filter>${basedir}/build.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>${basedir}/misc/jboss</directory>
                <filtering>true</filtering>
                <targetPath>${basedir}/filtered</targetPath>
                <includes>
                    <include>manager.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/misc/jboss</directory>
                <filtering>false</filtering>
                <targetPath>${basedir}/filtered</targetPath>
                <excludes>
                    <exclude>*.jar</exclude>
                    <exclude>*.keystore</exclude>
                    <exclude>*.xml</exclude>
                </excludes>
            </resource>
        </resources>
        ...
</build>

I notice that the beans.xml file is missing from the .war file. I don't understand why the beans.xml is missing, since I'm only applying the filering on a specific directory <directory>${basedir}/misc/jboss</directory>...

When I remove the above from the pom everything is working again. Any ideas?

Was it helpful?

Solution 2

The problem was indeed related to the <exclude>*.xml</exclude> as suggested by @cowls.

But the root cause was due to the fact that when there's at least one <resource> element then the default filtering behavior doesn't apply anymore. The default filtering behavior is to includer resources under src/main/resources in the build, without filtering. So without that default behavior, the beans.xml which was under src/main/resources wasn't included in the build, thus CDI stopped working.

In order to fix this issue, a 'default' resource had to be included:

<resource>
    <directory>src/main/resources</directory>
</resource>

More information can be found here.

OTHER TIPS

Looks like you're excluding all *.xml files from the build:

<exclude>*.xml</exclude>

Which is probably causing the problem.

I suspect you either want to remove the exclusions, or add corresponding include elements to the section with filtering set to true.

You probably also want to add a corresponding exclusion for

<include>manager.properties</include>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top