无法从命令提示符运行maven命令,但通过eclipse执行成功

时间:2017-09-21 12:29:55

标签: java maven selenium

我添加了所有依赖项(我的项目,junit等)和surefire插件。所以它在eclipse中成功执行但是当通过命令提示符运行时它会抛出错误。下面是附带的截图。和pom.xml文件。 eclipse works.maven中的嵌入式maven设置也从命令提示符中识别 BUILD FAILURE ERROR

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.selenium</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>

 <dependencies>

 <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>


<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server 
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>2.53.1</version>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/com.codeborne/phantomjsdriver -->
<dependency>
    <groupId>com.codeborne</groupId>
    <artifactId>phantomjsdriver</artifactId>
    <version>1.3.0</version>
</dependency>



  <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.1</version>
</dependency>

  <!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>



   <!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.5.6</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
    <groupId>org.uncommons</groupId>
    <artifactId>reportng</artifactId>
    <version>1.1.4</version>
    <scope>test</scope>
</dependency>
  <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>4.1.0</version>
</dependency>

  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

   <!-- Dependency for POI API -->
   <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.17</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>

  </dependencies>


    <build>
  <plugins>
  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <testFailureIgnore> false </testFailureIgnore>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/runner/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>

                </plugin>

        </plugins>
    </build>


</project>

2 个答案:

答案 0 :(得分:2)

从错误中,它说maven尝试从这个远程maven中心存储库下载一个依赖jar:https://repo.maven.apache.org/maven2/

由于此存储库是SSL网站,因此您需要安装其认证才能通过身份验证。 Maven由JDK运行,因此您需要将证书导入JDK Security Store。

你可以传入eclipse的原因是eclipse使用不同的settings.xml作为run maven命令,也许eclipse不使用SSL存储库。

有两种选择:
1)不要使用SSL maven远程存储库,在manve settings.xml中指定HTTP存储库:http://repo1.maven.org/maven2,如下所示:

<activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>securecentral</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>securecentral</id>
      <!--Override the repository (and pluginRepository) "central" from the
         Maven Super POM -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

2)在JDK Security Store中导入认证
    在这篇文章中找到要导入的步骤:     Problems using Maven and SSL behind proxy

答案 1 :(得分:1)

我认为你正在使用两个不同的maven,通常eclipse带有自己的maven版本。您可以验证您是否在eclipse和命令提示符下使用相同的Maven安装。

您可以通过转到来验证eclipse中的maven安装 偏好 - &GT;行家 - &GT;安装。

在命令提示符下,检查Maven home / M2 home。

Maven installation verify in eclipse