【问题标题】:NoClassDefFoundError when checkstyle is running运行 checkstyle 时出现 NoClassDefFoundError
【发布时间】:2013-08-27 20:40:16
【问题描述】:

我编写了一个新的 checkstyle 检查作为文件扫描器。我按照我在 checkstyle 代码中找到的代码对我的 junits 进行了建模。 junit 运行良好,一切看起来都很好。

然后,我将支票添加到我的项目中。

<module name="TreeWalker">
    <property name="tabWidth" value="4" />

    <module name="com.onuspride.codetools.checkstyles.DuplicateClassNames"/>
</module>

还有我的蚂蚁任务

<taskdef resource="checkstyletask.properties">
    <classpath refid="classpath" />
</taskdef>

<property name="checkstyle.suppressions.file" value="checkstyle/suppressions.xml" />
<property name="translation.severity" value="error" />

<target name="checkStyle" description="TestTask to evaluate the checkstyle system.">
    <checkstyle config="checkstyle/checkstyle_checks.xml">
        <fileset dir="${msg.src}" includes="**/*.java" />
        <formatter type="plain" />
        <formatter type="xml" toFile="${msg.build.jar}/checkstyle_errors.xml" />
        <classpath refid="classpath" />
    </checkstyle>
</target>

duplicateclassnames 类调用同一个 jar 中的多个类。由于某种原因,当ant运行它时,当它们都在同一个jar文件中时,ant找到了检查类,但找不到支持类。这就是我在蚂蚁中得到的东西

  [checkstyle] [class]:0: Got an exception - java.lang.NoClassDefFoundError: com/onuspride/codetools/common/classpath/criteria/ClassNameCriteriaCollector

我很难过。我检查了我的 jar 的所有依赖项,它们都在类路径中,我不明白它如何在同一个 jar 中找到一个类文件而不是另一个类文件。我已经做了所有肮脏的小把戏,我就是不明白。

有什么想法吗?

【问题讨论】:

  • 我不明白它如何在同一个 jar 中找到一个类文件而不是另一个类文件 :: 你能告诉你找到了哪个类,没有找到哪个类,在什么jar文件下。
  • 校验类是com.onuspride.codetools.checkstyles.DuplicateClassNames,找不到的类是,它们都包含在同一个jar中。 com.onuspride.codetools.common.classpath.criteria.ClassNameCriteriaCollector

标签: checkstyle


【解决方案1】:

你可以这样做:

  1. 创建插件项目并在那里添加您的自定义检查
  2. plugin.xmlcheckstyle_packages.xml. 进行适当的更改。
  3. 将项目导出为可部署插件和片段导出 > 插件开发
  4. 将 jar 文件复制到 Eclipse Plugin 文件夹,因此无需安装您的自定义检查

您可以通过this tutorial for reference

为减少工作量,请下载 Sample Check,文件名为 here,名称为 net.sf.eclipsecs.sample

只需替换 src 文件夹中的源代码即可。在替换之前,请参考 src/net/sf/eclipsecs/sample/checks/ 目录中的这 3 个文件,因为您将在 com/onuspride/codetools/checkstyles/ 中需要它们目录:

  1. checkstyle-metadata.properties
  2. checkstyle-metadata.xml
  3. messages.properties

替换代码后,对src/目录下的checkstyle_packages.xml文件进行适当的修改。

Extending Check 在那里描述得很好。

【讨论】:

  • 我会玩这个,但这个建议的问题是你假设我使用 Eclipse。我的大部分代码都是用 Wordpad 或 Sublime 编写的。
  • 是的,试过这个,但还是不行。同样,它没有任何问题找到我的支票,它很难找到我的支票需要的其他类。这些额外的检查在同一个 jar 文件中。
猜你喜欢
  • 2018-06-16
  • 1970-01-01
  • 1970-01-01
  • 2010-11-28
  • 1970-01-01
  • 1970-01-01
  • 2016-06-28
  • 2013-04-26
  • 2017-08-06
相关资源
最近更新 更多