exec-maven-plugin无法正确使用参数

时间:2018-10-22 17:49:22

标签: maven openldap exec-maven-plugin

我尝试执行带有一些参数的shell脚本(实际上是OpenLDAP的ldapmodify)。这是我在pom.xml中所做的事情:

在Maven配置文件中,我定义了一些值

<profile>
    <id>Linux-OpenLDAP</id>
         <activation>
             <os>
                  <family>Unix</family>
             </os>
         </activation>
    <properties>
        <OpenLdap.ClientTools.home></OpenLdap.ClientTools.home>
        <executable>/usr/local/bin/ldapmodify</executable>
        <argument>-a -x -h localhost -p 389 -D "cn=manager,dc=my-domain,dc=com" -f ${test-users.idif.path} -w secret</argument>
    </properties>
</profile>

这是我使用exec-maven-plugin的方式:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>${executable}</executable>
                        <arguments>
                            <commandlineArgs>${argument}</commandlineArgs>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

然后在mvn install之后,出现此错误:

[INFO] --- exec-maven-plugin:1.4.0:exec (default) @ entity-matching-bootstrap ---
/usr/local/bin/ldapmodify: invalid option -- ' '
ldapmodify: unrecognized option -
Add or modify entries from an LDAP server

如果我直接在公共行中运行/usr/local/bin/ldapmodify -a -x -h localhost -p 389 -D "cn=manager,dc=ibm,dc=com" -f /home/entity-matching/entity-matching-bootstrap/src/test/resources/test_users.ldif -w secret,它将成功。那么,为什么该选项在mvn安装期间无效?

1 个答案:

答案 0 :(得分:2)

问题是您将<commandlineArgs>嵌入了<arguments>部分中。只需删除<arguments>部分:

<configuration>
  <executable>${executable}</executable>
  <commandlineArgs>${argument}</commandlineArgs>
</configuration>