在 Eclipse 中运行 Maven Exec 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6079253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:11:28  来源:igfitidea点击:

Running Maven Exec Plugin Inside Eclipse

eclipsemavenmaven-pluginm2eclipse

提问by knpwrs

Using m2eclipse, what is the simplest way to use the Codehaus Mojo Exec Pluginto launch my project without leaving eclipse? So far on the pom plugins screen I have set up the org.codehuas.mojo plugin.

使用 m2eclipse,在不离开 eclipse 的情况下使用Codehaus Mojo Exec 插件启动我的项目的最简单方法是什么?到目前为止,在 pom 插件屏幕上,我已经设置了 org.codehuas.mojo 插件。

Specifically, I would like to execute the following from inside eclipse:

具体来说,我想从 eclipse 内部执行以下操作:

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main

回答by ilcavero

  1. go to Run menu -> run configurations
  2. you should see a "Maven Build" item on the list of the left, double click it to create a new configuration of that type
  3. name it as you want
  4. browse workspace to select the base directory of your project
  5. set exec:java as the goal, and exec.mainClass / yourClass as parameters.
  1. 转到运行菜单 -> 运行配置
  2. 您应该在左侧列表中看到一个“Maven Build”项目,双击它以创建该类型的新配置
  3. 随意命名
  4. 浏览工作区以选择项目的基本目录
  5. 将 exec:java 设置为目标,将 exec.mainClass / yourClass 设置为参数。

This is how it looks on my set-up:

这是它在我的设置中的样子:

enter image description here

在此处输入图片说明

PD: if you have set the mainClass argument on the pom.xml, then the parameter from the execution will be disregarded.

PD:如果你在 pom.xml 上设置了 mainClass 参数,那么执行的参数将被忽略。

回答by grin

In pom.xml set the target class:

在 pom.xml 中设置目标类:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                <configuration>
                       <mainClass>org.sonatype.mavenbook.weather.Main</mainClass>
                </configuration>
                </execution>
            </executions>

Then go to "Run as.. " -> "Maven build..." -> Goals "exec:java"

然后转到“Run as..”->“Maven build...”->目标“exec:java”

回答by Suchitto Palit

There's slight mistake in the pom.xml entry given by @grin. The correct one should be as follows:

@grin 给出的 pom.xml 条目中存在轻微错误。正确的应该是这样的:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
           <goals>
            <goal>java</goal>
           </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>org.sonatype.mavenbook.weather.Main</mainClass>
    </configuration>
</plugin>

回答by Manish

go to Run menu -> run configurations you should see a "Maven Build" item on the list of the left, double click it to create a new configuration of that type name it as you want browse workspace to select the base directory of your project set exec:java as the goal, and exec.mainClass / yourClass as parameters.

转到运行菜单 -> 运行配置,您应该在左侧列表中看到一个“Maven Build”项,双击它以创建该类型的新配置,将其命名为您想要浏览工作区以选择项目的基本目录将 exec:java 设置为目标,将 exec.mainClass / yourClass 设置为参数。

it worked for me Thanks !

它对我有用 谢谢!