简体   繁体   English

"如何在一个 Maven 命令中调用两个不同的配置文件?"

[英]How do I invoke two different profiles in one maven command?

I have two profiles for different environments in pom.xml<\/code> , I have to run mvn -PTest1 install<\/code> and mvn -PTest2 install<\/code> command to get these profiles in use.我在pom.xml<\/code>中有两个用于不同环境的配置文件,我必须运行mvn -PTest1 install<\/code>和mvn -PTest2 install<\/code>命令才能使用这些配置文件。 Can we integrate two separate maven commands in a single one (like mvn clean install<\/code> )?我们可以将两个单独的 maven 命令集成到一个命令中(例如mvn clean install<\/code> )吗?

Here is my Pom entry这是我的 Pom 条目

<profiles>
  <profile>
  <id>Test1</id>
  <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.5</jdk>
    <os>
       <name>Windows XP</name>
       <family>Windows</family>
       <arch>x86</arch>
       <version>5.1.2600</version>
    </os>
    <property>
       <name>sparrow-type</name>
       <value>African</value>
    </property>
  </activation>
  <dependencies>
    <dependency>
      <groupId>
      com.endeca
      </groupId>
      <artifactId>
      endeca_navigation_Test1
      </artifactId>
     <version>
     6.1
     </version>
     <!--<version>stable</version> -->
    <scope>
    compile
    </scope>
  </dependency>
  </profile>

  <profile>
    <id>Test2</id>
    <activation>
      <activeByDefault>false</activeByDefault>
      <jdk>1.5</jdk>
      <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
      </os>
      <property>
        <name>sparrow-type</name>
        <value>African</value>
      </property>
    </activation>
    <dependencies>
      <dependency>
        <groupId>
        com.endeca
        </groupId>
        <artifactId>
        endeca_navigation_Test2
        </artifactId>
        <version>
        6.1
        </version>
        <!--<version>stable</version> -->
        <scope>
        compile
        </scope>
      </dependency>
    </dependencies>
  </profile>
</profiles>

For me Mifeet's answer isn't working.对我来说,Mifeet 的回答不起作用。 I get "unknown lifecycle phase Test2".我得到“未知的生命周期阶段 Test2”。 For me this is working:对我来说,这是有效的:

mvn install -PTest1 -PTest2

Based on the maven help command基于 maven help 命令

 -P,--activate-profiles <arg>   Comma-delimited list of profiles to activate

This is not an answer, is to disccuss, how looks like the output of the command that works I try the @naXa, and I think it works only show this messages这不是一个答案,而是讨论,我尝试@naXa 的命令的输出看起来如何,我认为它只显示此消息

[WARNING] The requested profile "'test" could not be activated because it does not exist.
[WARNING] The requested profile "normal'" could not be activated because it does not exist.

Command that I run我运行的命令

mvn test -P 'test,normal'

so, the question is how do I identy that already run both profiles?所以,问题是我如何识别已经运行两个配置文件?

When I run the commando with double quotes doesn't show the warnings but I think that only execute the normal profile, because it shows当我用双引号运行突击队时不会显示警告,但我认为只执行普通配置文件,因为它显示

[INFO] Executing tasks
 [echo] Using env.properties
[INFO] Executed tasks

Something similar occurs when I use the versions propouse by @dermoritz, @sendon1982 and @Mifeet当我使用@dermoritz、@sendon1982 和@Mifeet 提出的版本时,也会发生类似的情况

mvn test -Ptest -Pnormal
mvn test -Ptest,normal

So I am not sure how should be look.所以我不确定应该怎么看。 Thanks for your help谢谢你的帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Maven,如何使用一个不同的.java文件构建两个版本的Java项目? - With Maven how do I build two versions of a Java project with just one different .java file? 如何在Maven中使用配置文件,分类器和模块正常工作? - How do I work correctly with profiles, classifiers and modules in Maven? 我如何告诉Maven与我的个人资料相比打包文件 - How do I tell Maven to package the file compared to my profiles 如何用不同的资源文件夹配置Maven配置文件? - How to configure Maven profiles with different resources folders? 如何使用Maven为不同的配置文件执行任务 - how to perform task for different profiles using maven Maven:在一个版本中对不同的模块使用不同的全局配置文件 - Maven: Use different global profiles for different modules in one build 如何使用不同的系统属性值执行两个完全相同的 maven 配置文件? - How to execute two exactly same maven profiles with a different system property value? 一战中多个Spring配置文件和Maven配置文件 - Multiple Spring profiles and Maven profiles in one war Maven 配置文件 - 如何获取分配给.properties 文件中的属性的值并将它们分配给我的 class 中的变量? - Maven Profiles - How do i get the values assigned to properties in the .properties file and assign them to variables in my class? 如何在flutter中将一个图标更改为两个不同的图标? - How do I change one icon into two different icons in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM