繁体   English   中英

Junit和Selenium的Maven编译错误

[英]Maven compile error for Junit and Selenium

为了与m2e bug /问题保持一致,我按照提到的解决方案@ SL4j m2e无法在Eclipse IDE中加载

我的Pom.xml看起来像这样(对于我的JUnit和Selenium依赖项):

<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>TestJUnit</groupId>
  <artifactId>TestJUnit</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <type>jar</type>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>2.41.0</version>
  <type>jar</type>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.10-FINAL</version>
</dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>2.41.0</version>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

但是,当我执行mvn compile我收到以下类型的错误:

[ERROR] /path:/to/file/<foldername>/<JUnitClassName>.java:[9,17] package org.junit does
 not exist

我是maven的新手,有什么我在这里做错了。

<dependencies>列表中,您指定了具有test范围的JUnit,这意味着它只在您执行mvn test时包含在jar中,但不包含在mvn compile 如果您希望JUnit包含在最终jar中,请将<scope>test</scope>更改为<scope>compile</scope>或者您可以删除tine,它们都会执行相同的操作。

TL; DR使用mvn test来测试你的应用程序; 或者在junit dependeny decleration中将<scope>test</scope>更改为<scope>compile</scope>

当我第一次开始使用maven时,我做了同样的事情,几乎每个人都这样做:P

暂无
暂无

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

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