Maven:如果pom.xml中属性标签中的句子 [英] Maven: If sentences in pom.xml in the property tag

查看:126
本文介绍了Maven:如果pom.xml中属性标签中的句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要设置环境变量,我想设置一个属性.我在其中搜索了很多内容,发现的内容与下面的代码类似,但是我不断收到错误消息:

I'd like to set a property if an environment variable is set. I googled a lot on it and all I found is something similar to the code below, but I keep getting the error:

[FATAL]不可解析的POM Y:\ Maven \ parent-pom \ pom.xml:TEXT必须紧跟END_TAG,而不是START_TAG(位置:START_TAG seen ... grosties"\ r \ n
classpathref ="maven.plugin.classpath"/> ... @ 29:55)@第29行,列 55

[FATAL] Non-parseable POM Y:\Maven\parent-pom\pom.xml: TEXT must be immediately followed by END_TAG and not START_TAG (position: START_TAG s een ...roperties"\r\n
classpathref="maven.plugin.classpath" />... @29:55) @ line 29, column 55

那是我正在尝试的代码,它位于pom.xml中,我运行了命令-

That's the code I'm trying, its inside a pom.xml and I ran the command -

mvn-错误部署

当然,如果您对如何根据环境变量内容在pom.xml中设置属性有其他建议,我将很高兴获得任何其他解决方案.

Of course, I'll be happy to get any other solution, if you have other suggestion on how to set a property in pom.xml depending on an environment variable content.

谢谢, 以利

    <distributionManagement>
       .....
    </distributionManagement>

    <properties>
          <tasks>
        <taskdef resource="net/sf/antcontrib/antcontrib.properties"
          classpathref="maven.plugin.classpath" />

        <if>
           <condition>
             <equals arg1="${env.WAS60_HOME}" arg2=""\>
           </condition>
           <then>
             <was60.home>${env.WAS60_HOME}</was60.home>
             <javac>${was60.home}/java/bin/javac</javac>
           </then>
        </if>

         <if>
           <condition>
             <equals arg1="${env.WAS85_HOME}" arg2=""\>
           </condition>
           <then>
             <was85.home>${env.WAS85_HOME}</was60.home>
             <javac>${was85.home}/java/bin/javac</javac>
           </then>
        </if>
      </tasks>
</properties>
    <profiles>
       <profile>
    <id>was.base.v60</id>
            <dependencies>
               <dependency>
                 ....
                  <systemPath>${was60.home}/java/jre/lib/xml.jar</systemPath>
               </dependency>
               .....
            </dependencies>
        </profile>
        <profile>
    <id>was.base.v85</id>
            <dependencies>
               <dependency>
                 ....
                  <systemPath>${was85.home}/java/jre/lib/xml.jar</systemPath>
               </dependency>
               .....
            </dependencies>
        </profile>
    </profiles>

推荐答案

显然,没有办法在Maven中执行正确的IF-THEN-ELSE语句.至少没有我发现的.

Apparently there is no way to do a proper IF-THEN-ELSE sentence in Maven. At least none that I found.

我发现最接近的东西是使用激活"标签.如果符合配置文件中的条件,它将激活该配置文件.

The closest thing I found was using the "activation" tag. which will activate the profile if the condition in it is met.

Maven 2.0.X在多种情况下存在一些错误,不确定现在的状态是什么-

There is some bug on multiple conditions in Maven 2.0.X, not sure what's the status of it now -

http://jira.codehaus.org/browse/MNG-4565

因此,这里的问题回答了一个代码示例-

So, a code example is answered on the question here -

Maven 2:运行maven-replacer-plugin有条件替换值?

但是,如果您想做类似<<如果...然后...其他>>您将要撞到墙上.当然,还有其他方法,我认为这是有目的的,因此您必须遵循Maven的方法.

But if you want to do something like << IF ... Then ... Else >> You're going to hit you head on a wall doing it. There are other ways, of course and I assume it is done in purpose, so you'll have to follow Maven way.

感谢所有尝试提供帮助的人 伊利亚胡(Elyahu)

Thanks to all that tried to help Elyahu

这篇关于Maven:如果pom.xml中属性标签中的句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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