我已经实现了一个Checkstyle Listener。它之前有用,(我认为5.0测试版发布),但是现在(5.0版),checkstyle失败并带有以下CallStack
Unable to create Checker: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module de.xyz.toxicity.TeamcityListener - Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:177)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:207)
at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:138)
at com.puppycrawl.tools.checkstyle.Main.main(Main.java:115)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListener
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:156)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:152)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate de.xyz.toxicity.TeamcityListenerCheck
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:99)
at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:153)
... 4 more
我的配置文件看起来像这样
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="de.xyz.toxicity.TeamcityListener" />
<module name="FileLength">
<property name="max" value="500"/>
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
<module name="AnonInnerLength">
<property name="max" value="35"/>
</module>
// ... more modules like this follow
</module>
</module>
当我从配置中删除自己的侦听器时,一切正常。
让我感到困惑的是:为什么checkstyle正在寻找TeamcityListenerCheck类? 这样的课程不存在。我需要它吗?它应该是什么样的?
答案 0 :(得分:1)
愚蠢的我......这是一个简单的类路径问题。
答案 1 :(得分:0)
您能否提供有关类路径问题的更多信息?我遇到了同样的问题。当我使用sun_checks.xml在ANT中运行Checkstyle时......没有问题。当我添加我的custom_check.xml时,我会看到相同的错误消息。当你说Classpath是指环境类路径,如%CLASSPATH%,还是指ANT文件中的类路径设置?
我的ANT文件设置如下:
<taskdef resource="checkstyletask.properties">
<classpath>
<pathelement location="\bin"/>
<pathelement location="\lib"/>
<!--<pathelement location="C:ant\lib\myCSCode.jar"/> -->
<pathelement location="C:\checkstyle-5.5\checkstyle-5.5-all.jar"/>
</classpath>
</taskdef>