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

时间:2014-10-14 07:10:48

标签: java maven maven-2 maven-3

我正处于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

1 个答案:

答案 0 :(得分:1)

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

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

然后它根据给定的目标使用jar来运行构​​建。

现在,在您的情况下,您必须找到一种连接到存储库的方法(检查位于用户目录的.m2文件夹中的settings.xml)并检查是否可以连接到Internet中央maven存储库。如果没有,您可以获取jar文件并按照您所遇到的错误中的建议手动安装它们。一旦你这样做,我认为你应该通过这个问题。如果您仍有问题,请告诉我。