使用“mvn test”从命令行运行会在找不到依赖 jar 的情况下出现错误

用户10829672

我有两个项目。AutomationFramework 只是库/公共页面/基类等。我从中创建了一个 jar 并添加到主测试项目,即自动化测试套件。我可以从 Eclipse (2021-06) 成功运行所有 7 个测试。我喜欢从命令行运行它们,然后将其设置为从 Jenkins 运行。当输入“ mvn test ”时出现此错误:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[6,54] package com.agricorp.AutomationResourcesFramework.Base does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[7,57] package com.agricorp.AutomationResourcesFramework.Globals does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[8,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[9,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[11,58] cannot find symbol
  symbol: class Base
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[10,54] package com.agricorp.AutomationResourcesFramework.Base does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[11,57] package com.agricorp.AutomationResourcesFramework.Globals does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[12,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[13,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[14,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[16,56] cannot find symbol
  symbol: class BasePageSetup

错误信息

顺便说一句,我已经从命令行成功清理和编译(使用mvn cleanmvn compile)。同样,我注意到它在上面寻找 .java 源文件。“mvn verify”也给出了上述错误。

通过 Eclipse 中的项目设置”

Eclipse 项目结构

      <name>AutomationResourcesFramework</name>
      <!-- FIXME change it to the project's website -->
      <url>http://www.example.com</url>

      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>

      <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency> 
        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.14.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.14.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <!--scope>test</scope-->
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>5.0.8</version>
        </dependency>           
        <!-- https://mvnrepository.com/artifact/com.codoid.products/fillo -->
        <dependency>
            <groupId>com.codoid.products</groupId>
            <artifactId>fillo</artifactId>
            <version>1.21</version>
        </dependency>
      </dependencies>

        <profiles>
            <profile>
                <id>SanityTests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M5</version>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>testng.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>RegressionTests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M5</version>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>FBRAutomationTestSuite.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>

      <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
          <plugins>
            <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
            <plugin>
              <artifactId>maven-clean-plugin</artifactId>
              <version>3.1.0</version>
            </plugin>
            <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>3.0.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.8.0</version>
            </plugin>
            <plugin>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.0.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-install-plugin</artifactId>
              <version>2.5.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-deploy-plugin</artifactId>
              <version>2.8.2</version>
            </plugin>
            <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
            <plugin>
              <artifactId>maven-site-plugin</artifactId>
              <version>3.7.1</version>
            </plugin>
            <plugin>
              <artifactId>maven-project-info-reports-plugin</artifactId>
              <version>3.0.0</version>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </project>
杰罗德·布罗瑟

AFAICS,<dependency>您的FBRAutomationTestSuite项目中没有引用AutomationResourcesFramework工件,例如:

        <dependency>
            <groupId>com.agricorp</groupId>
            <artifactId>automation-resources-framework</artifactId>
            <version>...</version>
        </dependency>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

不能与Maven命令行运行jar文件

从命令行运行jar时出现MessageBodyProviderNotFoundException

从命令行使用依赖项运行jar

从命令行运行JAR文件并指定类路径

无法从命令行运行jar文件:“无主清单属性”

为什么从命令行运行的可执行jar比从Eclipse运行的同一项目使用更多的ram?

在没有GUI的情况下从命令行运行JavaFX应用

从命令行运行爆炸的spring-boot jar

scalac错误:错误的选项:通过命令行在mvn软件包上使用'-make:transitive'

在Windows上不运行pub的情况下出现webdev错误

为什么不会在缺少属性的情况下出现编译器错误?

使用库时,在生产模式下出现“错误:找不到模块'@ app / foo'”

创建JAR文件后,命令行返回“错误:找不到或加载主类ExampleProgram”?

从命令行运行时出现ModuleNotFoundError

从命令行运行Jar:ClassNotFoundException

使用相同的方法名称但使用import static具有不同签名的情况下出现意外的编译错误

从命令行运行“ takeown”时,为什么会出现特权错误?

使用PHP的mail()是从命令行运行的,而不是从Apache运行的,为什么?

从命令行运行jar会导致FileNotFoundException

为什么我在rpm脚本中出现“ [...] 2>>(tee -a $ logfile>&2)[...]”的语法错误,但是从命令行运行时却找不到语法错误,以及如何使其正常工作?

使用java -jar \ target \ demo-0.0.1-SNAPSHOT.jar从命令行运行spring boot应用程序时出错

从命令行运行mfp时在Mac上找不到命令错误

尝试以编程方式使用data.table时,在特定情况下出现“在1级没有这样的索引”错误

如何在不使用命令行运行的情况下以编程方式为 JMeter 设置代理设置

如何在不使用 mvn exec:java 之类的东西的情况下,在打开控制台 (cmd) 的情况下启动不可运行的 Java 文件 (.jar) 以显示输出

如何从命令行运行从 Intellij 创建的 Java JAR

从命令行运行时,weld-se 无法在类路径上的不同 jar 中找到 bean

在没有 Maven 码头的情况下从命令行运行战争

在使用命令行运行程序的 Spring Boot 中创建一个 jar 文件