我需要使用windows格式传递一个目录作为maven上exec的参数,下面是pom.xml文件的摘录。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>export</id>
<phase>deploy</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<escape>true</escape>
<executable>${cmdl.exec}</executable>
<workingDirectory>${cmdl.location}</workingDirectory>
<arguments>
<argument>${project.basedir}\\target\\classes\\publishRoute</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
我遇到的问题是${project.basedir}解析为单斜杠:
cmd /c script_cmdline.bat C:\Talend_CI\talend\release\Routes\SimpleRoute\\target\\classes\\publishRoute
我需要用双反斜杠传递它。如何使用${project.basedir}实现这一点?
3条答案
按热度按时间cngwdvgl1#
你有一种方法来重载变量或声明一个新变量来表示项目basedir,如下所示:
23c0lvtd2#
在看了几篇与这个问题相关的文章之后,似乎唯一有效的方法就是使用属性列表并相应地使用它们来实现分析。虽然不是一个优雅的解决方法,但它为您提供了动态分配文件路径的选项,而不管用于运行maven的操作系统/平台。
brgchamk3#
如果要调用的外部工具可以 Package 到脚本或批处理文件中,则可以使用带有单个反斜杠或正斜杠的
${basedir.home}\...
将路径传递到 Package 器,然后根据命令的需要规范化 Package 器中的参数。换句话说:不要试图在POM或Maven核心中解决问题(这是不切实际的),在shell中解决它。你也可以试试这个:https://www.bennorthrop.com/Snippets/string-replace-in-maven-with-regex.php