Java 在Eclipse中运行带有JUnit项目的Maven时出错
当我试图在eclipse项目中运行带有JUnit的Maven测试时,我遇到以下错误:Java 在Eclipse中运行带有JUnit项目的Maven时出错,java,eclipse,maven,junit,Java,Eclipse,Maven,Junit,当我试图在eclipse项目中运行带有JUnit的Maven测试时,我遇到以下错误: [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building exemplo-maven 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ exemplo-maven ---
[INFO] Deleting C:\Users\vcamargo\workspace\exemplo-maven\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ exemplo-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ exemplo-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\vcamargo\workspace\exemplo-maven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ exemplo-maven ---
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/maven-surefire-common/2.12.4/maven-surefire-common-2.12.4.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain/2.0.9/maven-toolchain-2.0.9.pom
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugin-tools/maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.470 s
[INFO] Finished at: 2017-02-27T10:08:30-03:00
[INFO] Final Memory: 19M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project exemplo-maven: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4 -> org.apache.maven.surefire:surefire-booter:jar:2.12.4: Failed to read artifact descriptor for org.apache.maven.surefire:surefire-booter:jar:2.12.4: Could not transfer artifact org.apache.maven.surefire:surefire-booter:pom:2.12.4 from/to central (https://repo.maven.apache.org/maven2): RSA premaster secret error: SunTls12RsaPremasterSecret KeyGenerator not available -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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 read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
下面是my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.algaworks.curso</groupId>
<artifactId>exemplo-maven</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<killAfter>-1</killAfter>
<mainClass>com.algaworks.curso.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
最后是我的测试课:
package com.algaworks.curso;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class FibonacciTest {
@Test
public void deve_retornar_fibonacci_posicao_1() {
assertEquals(1L, 1L);
}
}
当我单独运行测试类时,它运行得非常完美。如果我尝试在没有测试的情况下运行一个Maven项目(目标:exec:java),它也会运行得很好
当我尝试运行带有JUnit测试的Maven项目时(目标:clean project),错误就发生了。从您发布的日志来看,问题似乎不在于JUnit测试用例,但是您的maven无法下载一些工件。在repo中,我可以看到maven surefire booter jar的所需版本。我猜网络防火墙或连接存在一些问题…我们可以尝试重新连接到网络,然后运行目标吗?错误表示surefire插件直接或间接使用的依赖项无法解决。我从未遇到过这个错误,但是,请从以下位置删除您的maven surefire插件文件夹:“.m2\repository\org\apache\maven\plugins” 并重新运行构建,该构建将自动重新下载所有插件文件。
在删除之前,请确保备份文件夹,以便分析丢失的内容。尝试从终端运行文件夹时会发生什么情况?我不知道如何从终端运行文件夹。我正在Eclipse中使用Maven插件,如果我配置为在没有测试的情况下运行(目标:exec:java),它会运行得很好。尝试从项目目录运行
mvn clean install
,其中包括pom.xml
(安装Maven后)
package com.algaworks.curso;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class FibonacciTest {
@Test
public void deve_retornar_fibonacci_posicao_1() {
assertEquals(1L, 1L);
}
}