简体   繁体   English

无法将参数从命令行传递到Maven项目。 我想传递可以运行测试的服务器URL

[英]Not able to pass parameter from command line to maven project. I want to pass server url on which I can run my test

I have created Maven project for the first time and I was able to run it previously without passing parameter by using mvn test command. 我是第一次创建Maven项目,并且以前可以使用mvn test命令运行它而无需传递参数。
Now I want to pass parameter to it so i changes pom.xml but getting following error 现在我想将参数传递给它,所以我更改pom.xml但出现以下错误

BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.209 s
[INFO] Finished at: 2014-12-23T12:52:44+05:30
[INFO] Final Memory: 5M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal 'exec' in plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 among available goals help, compile, testCompile -> [Help 1]
org.apache.maven.plugin.MojoNotFoundException: Could not find goal 'exec' in plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 among available goals help, compile, testCompile
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor(DefaultMavenPluginManager.java:273)
    at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor(DefaultBuildPluginManager.java:239)
    at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:233)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:103)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:83)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:85)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException

Here is my pom.xml 这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/3.2.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/3.2.3 http://maven.apache.org/xsd/maven-3.2.3.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Grok</groupId>
  <artifactId>MobileApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Login to app</name>
  <description>Login to Grok app</description>

  <repositories>
    <repository>
        <id>saucelabs-repository</id>
        <url>https://repository-saucelabs.forge.cloudbees.com/release</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

  <dependencies>
  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.44.0</version>
    </dependency>  
    <dependency>
     <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
     <groupId>com.saucelabs</groupId>
     <artifactId>sauce_junit</artifactId>
     <version>2.1.3</version>
     <scope>test</scope>
    </dependency>
  </dependencies>

   <build>
   <pluginManagement>
        <plugins>
            <!-- Include Sauce Connect plugin -->
            <plugin>
                <groupId>com.saucelabs.maven.plugin</groupId>
                <artifactId>sauce-connect-plugin</artifactId>
                <version>2.1.9</version>
                <configuration>
                    <sauceUsername>admins-test-numenta</sauceUsername>
                    <sauceAccessKey>f6c91fa5-d400-42be-85e1-f7060098f922</sauceAccessKey>
                    <options>-i testing</options>
                </configuration>
                <executions>
                    <execution>
                        <id>start-sauceconnect</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-sauceconnect</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-sauceconnect</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop-sauceconnect</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>exec-one</id>
                        <phase>verify</phase>
                        <configuration>
                            <executable>echo</executable>
                            <variables>
                          <variable>serverUrl:${Gvars.server}</variable>
                        </variables>
                        </configuration>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <executions>
                <execution>
                    <configuration>
                         <variables>
                              <variable>serverUrl:${RFvars.browser}</variable>
                            </variables>
                    </configuration>

                     <goals>
                                <goal>exec</goal>
                            </goals>
                            </execution>
                            </executions>
                </plugin>
            </plugins> 
           </pluginManagement> 
    </build>         
</project>

I am running this from command line 我从命令行运行

mvn org.apache.maven.plugins:maven-compiler-plugin:exec -DGvars.server=url_to_be_used

Please let me know if I am doing anything wrong in pom file or in command to run project. 如果我在pom文件或运行项目的命令中做任何错误,请让我知道。 Thanks in advance 提前致谢

The problem is with your maven-compiler-plugin configuration. 问题出在您的maven-compiler-plugin配置上。 As the error message states the compiler plugin does not have an exec goal ( Could not find goal 'exec' in plugin org.apache.maven.plugins:maven-compiler-plugin ). 如错误消息所示,编译器插件没有exec目标( Could not find goal 'exec' in plugin org.apache.maven.plugins:maven-compiler-plugin )。

It only has two goals available and these are: 它只有两个目标可用,分别是:

  • compile
  • testCompile

Also I'm not sure what you expect the compiler plugin to do with the variables configuration. 另外,我不确定您希望编译器插件如何使用variables配置。 It doesn't know about variables so will ignore it. 不了解 variables因此将忽略它​​。

Change your compiler-plugin configuration to be as follows: 更改您的编译器插件配置,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
        <execution>
           <goals>
               <goal>compile</goal>
           </goals>
        </execution>
    </executions>
</plugin>

But actually this is the default configuration so you can simplify it even further to just be: 但这实际上是默认配置,因此您可以将其进一步简化为:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
</plugin>

I am not updating my pom.xml 我没有更新我的pom.xml

Just using @Parameters({"url", "pwd"}) annotation of Testng 仅使用@Parameters({"url", "pwd"})批注

Its working for me. 它为我工作。

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

相关问题 我想编写一个将mvn clean test命令作为输入的shell脚本,当我运行该脚本时,它应该运行我的maven项目 - I want to write a shell script which will take mvn clean test command as input and when I run the script , it should run my maven project 我如何将命令行选项传递给phantomjs Maven插件 - How can i pass command line option to phantomjs maven plugin 如何将命令行参数传递给 Maven 程序的执行? - How can I pass a command line argument to the execution of a Maven program? 我不能运行我的Maven项目 - I am Not Able to run my Maven Project 我可以在JSP的URL中将列表作为参数传递吗? - Can I pass a List as parameter in a URL in JSP? 如何从命令行将 VM arguments 传递给 gradle? - How can I pass VM arguments to gradle from command line? 如何将参数从 jenkins 传递给 Maven 项目 - How to pass parameter to maven project from jenkins 如何从命令行从Maven的测试文件夹中运行单个类? - How do i run a single class from the test folder of Maven from the command line? 我的配置pom.xml跳过了测试。 但是现在我想用命令行运行一次测试。 命令如何? - My configuration pom.xml has skipped test. But now I want to run test once with command line. How is the command? 我想从我的本地主机运行一个项目 - I want to run a project from my localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM