通过Maven构建配置文件选择类 [英] Selecting class by Maven build profile

查看:204
本文介绍了通过Maven构建配置文件选择类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢Maven和Java EE编程。



我想为默认的Maven构建配置文件中激活验证测试创建一个存根类。



目前我有两个同名的课程,但是在不同的包中。是否可以通过设置maven构建配置文件参数在构建阶段选择正确的类来使用?我也在我的项目中使用EJB和JSF2.0,并在其中一个bean中创建身份验证对象:

  AuthUtil util = new AuthUtil(); 


解决方案

有可能,有一些脚步。您必须将您的课程放在依赖关系中,并以这种方式使用个人资料:

 <个人资料> 
<个人资料>
< id> default< / id>
<依赖关系>
< dependency> ...< / dependency>
< / dependencies>
< / profile>
<个人资料>
< id> someotherprofile< / id>
<依赖关系>
< dependency> ...< / dependency>
< / dependencies>
< / profile>
< / profiles>

此外,这些类必须在同一个包中才能正常工作。



干杯,


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();

解决方案

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,

这篇关于通过Maven构建配置文件选择类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆