Skip to content
Advertisement

Selecting class by Maven build profile

I am quite new to Maven and Java EE programming all-together.

I would like to create a stub class for authentication testing which should be activated in the default Maven build profile.

Currently I have two classes with same name but in different packages. Is it possible to somehow select the correct class to use in the build phase by setting maven build profile parameters? I am also using EJB and JSF2.0 in my project and the authentication object is created in one of the beans:

AuthUtil util = new AuthUtil();

Advertisement

Answer

It is possible, with some footwork. You will have to put your class(es) in a dependency and use the profiles in this manner:

<profiles>
    <profile>
        <id>default</id>
        <dependencies>
             <dependency>...</dependency>
       </dependencies>
    </profile>
    <profile>
        <id>someotherprofile</id>
        <dependencies>
             <dependency>...</dependency>
       </dependencies>
    </profile>
 </profiles>

Also, the classes will have to be in the same package for this to work.

Cheers,

Advertisement