简体   繁体   English

如何从命令行执行maven插件?

[英]How to execute maven plugin from command line?

Is it possible to execute a Maven plugin from the command line? 是否可以从命令行执行Maven插件? I need to run dependency plugin: 我需要运行依赖插件:

<executions>
    <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <outputDirectory>${RPTBIN}/.tools/lib</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overWriteIfNewer>
            <excludeTransitive>true</excludeTransitive>
        </configuration>
    </execution>
</executions>

Is there any way to execute this plugin just like this plugin executes during Maven build? 有没有办法执行这个插件就像这个插件在Maven构建期间执行一样?

Yes that is possible. 是的,这是可能的。 Maven is a Java tool, so you must have Java installed in order to proceed. Maven是一个Java工具,因此您必须安装Java才能继续。 Please go through the installation process here . 在此处完成安装过程。

mvn dependency:copy-dependencies

A sample dependency plugin command. 示例依赖项插件命令。 By the way how you have been running the Maven command till now? 顺便说一下你到现在为止如何运行Maven命令?

您应该只能使用mvn dependency:copy-dependencies来运行它mvn dependency:copy-dependencies ,只需使用-Dparameter=value添加相关的配置参数,即-DoverWriteReleases=false

You can use below command. 您可以使用以下命令。 It worked for me: 它对我有用:

mvn {your groupId}:{your artifactId}:{your version}:{your goal} mvn {your groupId}:{your artifactId}:{your version}:{your goal}

But remember this command is good if your plugin main class is extending AbstractMojo. 但是请记住,如果您的插件主类正在扩展AbstractMojo,那么此命令就很好。

It will run the execute() method of your plugin main class. 它将运行插件主类的execute()方法。 Also, before running this command please run mvn clean install to build the jar 另外,在运行此命令之前,请运行mvn clean install来构建jar

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM