java 运行 jenkins 给出“包 org.junit 不存在”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6328529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:25:26  来源:igfitidea点击:

Running jenkins gives "package org.junit does not exist"

javaantjunitjenkins

提问by Manoel

Can any one please help me with that error?

任何人都可以帮我解决这个错误吗?

build-project:
     [echo] AntProject: /root/.jenkins/jobs/Ant/workspace/build.xml
    [javac] Compiling 2 source files to /root/.jenkins/jobs/Ant/workspace/bin
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:3: package org.junit does not exist
    [javac] import static org.junit.Assert.*;
    [javac]                        ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:5: package org.junit does not exist
    [javac] import org.junit.Test;
    [javac]                 ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:9: cannot find symbol
    [javac] symbol  : class Test
    [javac] location: class com.moi.test.junit.MaClasseTest
    [javac]     @Test
    [javac]      ^
    [javac] /root/.jenkins/jobs/Ant/workspace/src/com/moi/test/junit/MaClasseTest.java:12: cannot find symbol
    [javac] symbol  : method assertTrue(boolean)
    [javac] location: class com.moi.test.junit.MaClasseTest
    [javac]              assertTrue(MaClasse.additioner(2,2) == 4); 
    [javac]              ^
    [javac] 4 errors

BUILD FAILED /root/.jenkins/jobs/Ant/workspace/build.xml:35: Compile failed; see the compiler error output for details.

回答by Jigar Joshi

it seems you forgot to make junit library available in your classparh

您似乎忘记在 classparh 中提供 junit 库

回答by Quentin

My solution :

我的解决方案:

  • Download junit.jar
  • In the projet.properties file, find the line "javac.test.classpath=\" and add at the end /your/path/to/junit-4.10.jar
  • you can test locally to see if it works
  • push on github
  • build on jenkins and voila it works :)
  • 下载 junit.jar
  • 在 projet.properties 文件中,找到“javac.test.classpath=\”行并在末尾添加 /your/path/to/junit-4.10.jar
  • 你可以在本地测试看看它是否有效
  • 在 github 上推送
  • 建立在詹金斯和瞧它的工作原理:)

回答by Abdull

I ran into this problem because I accidentally put the failing JUnit testJava source file to location src/main/java/...instead of the correct src/test/java/....

我遇到了这个问题,因为我不小心将失败的JUnit 测试Java 源文件放到 locationsrc/main/java/...而不是正确的src/test/java/....

My IDE Eclipsedidn't complain about missing imports and would happily run tests from that file while it was located at src/main/java/...— while Jenkins would abort building, and therefore testing.

我的 IDE Eclipse没有抱怨缺少导入,并且很乐意在该文件所在的位置运行测试src/main/java/...- 而 Jenkins 会中止构建,从而中止测试。

Moving the problematic file to the correct location, src/test/java/..., resolved my issue.

将有问题的文件移动到正确的位置src/test/java/...,解决了我的问题。

回答by Thorbj?rn Ravn Andersen

You need to provide a compilation classpath to javac, which includes junit.jar.

您需要为 javac 提供一个编译类路径,其中包括 junit.jar。

Check the <classpath>tag inside <javac>for one way to solve this.

检查<classpath>内部的标签<javac>以找到解决此问题的一种方法。