繁体   English   中英

缺少 JUNIT Jar 使用 Maven 构建项目时出现异常

[英]Missing JUNIT Jar Exception while building project using Maven

我在Maven的开始阶段。我创建了一个项目并尝试使用该命令。 我最后缺少什么? 我正在尝试编译并运行一个 TestSuite 文件:

mvn clean package

POM.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test.myProject</groupId>
  <artifactId>myTest</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>egdsvTest</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

但我在使用它后得到以下异常。

例外

 D:\MVN_Shirish_Project\Test>mvn clean package
    [INFO] Scanning for projects...
    [INFO]
    [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethrea
    ded.SingleThreadedBuilder with a thread count of 1
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Test 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Test ---
    [INFO] Deleting D:\MVN_Shirish_Project\Test\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Test
    ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
    i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:\MVN_Shirish_Project\Test\src\
    main\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Test ---

    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
    uild is platform dependent!
    [INFO] Compiling 1 source file to D:\MVN_Shirish_Project\Test\target\classe
    s
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ eg
    dsvTest ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
    i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:\MVN_Shirish_Project\Test\src\
    test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ 
    Test ---
    [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
    uild is platform dependent!
    [INFO] Compiling 1 source file to D:\MVN_Shirish_Project\Test\target\test-c
    lasses
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Test ---
    [INFO] Surefire report directory: D:\MVN_Shirish_Project\Test\target\surefi
    re-reports
    [WARNING] Missing POM for org.apache.maven.surefire:surefire-junit3:jar:2.12.4
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.968 s
    [INFO] Finished at: 2014-10-14T12:28:09+05:30
    [INFO] Final Memory: 7M/247M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
    12.4:test (default-test) on project Test: Unable to generate classpath: org
    .apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
    [ERROR] ----------
    [ERROR] 1) org.apache.maven.surefire:surefire-junit3:jar:2.12.4
    [ERROR]
    [ERROR] Try downloading the file manually from the project website.
    [ERROR]
    [ERROR] Then, install it using the command:
    [ERROR] mvn install:install-file -DgroupId=org.apache.maven.surefire -DartifactI
    d=surefire-junit3 -Dversion=2.12.4 -Dpackaging=jar -Dfile=/path/to/file
    [ERROR]
    [ERROR] Alternatively, if you host your own repository you can deploy the file t
    here:
    [ERROR] mvn deploy:deploy-file -DgroupId=org.apache.maven.surefire -DartifactId=
    surefire-junit3 -Dversion=2.12.4 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url
    ] -DrepositoryId=[id]
    [ERROR]
    [ERROR] Path to dependency:
    [ERROR] 1) dummy:dummy:jar:1.0
    [ERROR] 2) org.apache.maven.surefire:surefire-junit3:jar:2.12.4
    [ERROR]
    [ERROR] ----------
    [ERROR] 1 required artifact is missing.
    [ERROR]
    [ERROR] for artifact:
    [ERROR] dummy:dummy:jar:1.0
    [ERROR]
    [ERROR] from the specified remote repositories:
    [ERROR] m1 (http://repo1.maven.org/maven2, releases=true, snapshots=false)
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
    xception

Maven的工作方式是在您的桌面或已安装maven的计算机上创建本地存储库并运行此目标。

在执行目标的Maven过程中,它首先尝试从中央存储库中获取您在注释M1或M2中列出的所有相关jar文件,然后将它们存储在C:/ Users /您的名字/.m2/repository文件夹下( (如果您使用的是Windows计算机)或其他OS系统中的相应用户文件夹。

然后,根据给定的目标,使用jars运行构建。

现在,以您的情况为例,您必须找到一种连接到存储库的方法(检查位于用户目录.m2文件夹中的settings.xml),并检查是否可以连接到Internet中央Maven存储库。 如果没有,您可以获取jar文件并按照错误提示操作手动安装它们。 一旦这样做,我认为您应该克服这个问题。 让我知道您是否还有问题。

就我而言,这是由于我进行了离线构建(即mvn -o install )并且我还没有在我的本地 Maven 存储库中安装 jar 造成的。 进行在线构建( mvn install )修复了它。

暂无
暂无

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

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