突然无法从 ant 运行 TestNG 测试([testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException)

发布于 2024-11-30 04:07:14 字数 1413 浏览 0 评论 0原文

我正在使用 ant 和 TestNG 6.1.1,昨天我的测试工作得很好。今天,当我尝试运行测试时,我收到涉及 com/beust/jcommander/ParamException 的 NoClassDefFoundError。这是输出:

[copy] Copying 1 file to /Users/djohnson/src/webapp/components/build/tmp
[testng] Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
[testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
[testng]    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[testng]    at java.security.AccessController.doPrivileged(Native Method)
[testng]    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[testng]    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[testng] The tests failed.

这是我正在使用的 .xml 文件:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Single Method Suite">
  <test name="Single Method Test">
    <classes>
      <class name="DhcpTest">
        <methods>
          <exclude name=".*" />
          <include name="setGetEnabledTest" />
        </methods>
      </class>
    </classes>
  </test>
</suite>

我还指定了该类的完整路径,但没有成功。我检查了类路径,一切看起来都很好,有人对此有什么想法吗?

I am using ant and TestNG 6.1.1, and I had my tests working just fine yesterday. Today when I try to run the tests I get a NoClassDefFoundError involving com/beust/jcommander/ParamException. Here is the output:

[copy] Copying 1 file to /Users/djohnson/src/webapp/components/build/tmp
[testng] Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
[testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
[testng]    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[testng]    at java.security.AccessController.doPrivileged(Native Method)
[testng]    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[testng]    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[testng] The tests failed.

Here is the .xml file I'm using:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Single Method Suite">
  <test name="Single Method Test">
    <classes>
      <class name="DhcpTest">
        <methods>
          <exclude name=".*" />
          <include name="setGetEnabledTest" />
        </methods>
      </class>
    </classes>
  </test>
</suite>

I've also specified the complete path for the class with no luck. I've checked the classpath and everything seems fine, does anyone have any ideas on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

以可爱出名 2024-12-07 04:07:14

如果您使用 ant,JCommander 应该位于 testng.jar 内,因此我认为您的 testng.jar 文件可能已损坏。

If you're using ant, JCommander should be inside testng.jar, so I'm thinking your testng.jar file might be corrupt.

通知家属抬走 2024-12-07 04:07:14

如果您使用 Maven,请尝试将其添加到您的 pom.xml

<dependency>
  <groupId>com.beust</groupId>
  <artifactId>jcommander</artifactId>
  <version>1.30</version>
</dependency>

If your using Maven try adding this to your pom.xml

<dependency>
  <groupId>com.beust</groupId>
  <artifactId>jcommander</artifactId>
  <version>1.30</version>
</dependency>
冷默言语 2024-12-07 04:07:14

jcommander.jar(例如 jcommander-1.29.jar)应该存在于 build.xml 中提到的文件集目录中

您可以从以下位置下载它: http://mvnrepository.com/artifact/com.beust/jcommander/1.27

或者,

在使用 ant 期间,JCommander 应该位于 testng.jar 内。您的 testng.jar 文件可能已损坏,因此请用新的 testng.jar 替换旧的 testng.jar。

jcommander.jar (e.g. jcommander-1.29.jar) should be present on fileset directory which is mentioned at build.xml

You can download it from: http://mvnrepository.com/artifact/com.beust/jcommander/1.27

OR,

JCommander should be inside testng.jar during using ant. Your testng.jar file might be corrupted, so please replace old testng.jar by new one.

靖瑶 2024-12-07 04:07:14

可能是 testng.jar 不在类路径中。

May be testng.jar is not in classpath.

眼眸 2024-12-07 04:07:14

我在非 Maven 项目中也遇到了同样的问题。我从 Maven Central 检索了 testng jar,但它不包含 TestNG 的所有依赖项。直接从 TestNG 站点下载 jar 解决了该问题,因为它包含依赖项。

我应该更加注意 TestNG 下载页面 上的说明...

最新版本的 TestNG 可以从 Maven Centralant 用户的此处下载。

I had this same problem with a non-Maven project. I retrieved the testng jar from Maven Central, but it didn't contain all of TestNG's dependencies. Downloading the jar directly from the TestNG site resolved the issue, as it contains the dependencies.

I should have paid more attention to the directions on TestNG's download page...

The latest version of TestNG can be downloaded from Maven Central or here for ant users.

如若梦似彩虹 2024-12-07 04:07:14

这里的问题是某些版本的 testNG jar 内部没有 jcommander jar 代码。因此,您必须单独将类路径添加到 Jcommander jar 中。

运行时将 Jcommander jar 添加到类路径中可以解决问题,希望如此

The problem here is that certain versions of the testNG jar do not have the jcommander jar code inside of them. As a result, you have to add the classpath to the Jcommander jar separately.

Adding the Jcommander jar to your classpath when you run it will fix the problem, hopefully

鼻尖触碰 2024-12-07 04:07:14

当我从以下位置下载 jcommandar jar 后,我的 ant 开始工作
Maven 存储库并将其添加到我的 jar 文件中

但是这个问题
开始附带 testng 6.8.5 版本

My ant start working when I have downloaded jcommandar jar from
Maven repository and added it in my jar file

But This problem
Starts coming with testng 6.8.5 version

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文