使用maven-exec-plugin运行命令行

时间:2015-12-02 19:37:22

标签: maven pom.xml maven-plugin pandoc exec-maven-plugin

我想使用maven-exec-plugin运行命令行(cmd),使用Pandoc将Markdown文件转换为PDF文件。

为了手动执行此操作,我执行了以下命令:

pandoc ReadMe.md -o ReadMe.html
pandoc ReadMe.html --latex-engine=xelatex -o ReadMe.pdf

我无法在一个命令中运行它,pandoc给出了奇怪的错误!但这是另一个问题...

我已经使用网络上的其他样本将此添加到我的pom文件中,但没有成功。

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>pandoc</id>
                    <phase>generate-pdf</phase>
                    <configuration>
                        <executable>cmd</executable>
                        <workingDirectory></workingDirectory>
                        <arguments>
                            <argument>/C</argument>
                            <argument>pandoc</argument>
                            <argument>README.md</argument>
                            <argument>-o</argument>
                            <argument>README.html</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>                            
            </executions>
        </plugin>   
    </plugins>
</build>

我不是一位专家,很感激帮助!

1 个答案:

答案 0 :(得分:4)

定义的阶段<phase>generate-pdf</phase>不是maven阶段,因此Maven没有将执行绑定到其工作流程。

您应该根据需要将其绑定到标准Maven阶段。例如,尝试使用<phase>package</phase>,它几​​乎会在构建结束时执行。

插件执行的id元素是自由文本,您可以键入所需的ID,它将在插件和目标名称后的弯曲括号中显示为构建输出的一部分,

即。 exec-maven-plugin:1.1:exec (pandoc)

phase元素必须匹配一个众所周知的maven阶段,以便将插件/目标执行附加到它。如果阶段不为人所知,那么Maven将简单地忽略该插件/目标执行(这也是一种采用的方法,通常使用事实上的标准none作为阶段)来禁用继承的插件执行,但是#39;我想说这个问题的范围有点先进。

有关maven阶段的更多详细信息,请查看官方文档here。 有关maven阶段的完整列表,here