【问题标题】:Checkstyle error on Unix only仅 Unix 上的 Checkstyle 错误
【发布时间】:2012-04-05 05:11:30
【问题描述】:

我正在使用 Ant 为 */.html 文件运行基于自定义正则表达式的检查。这是非常简单的配置。 Ant build.xml:

<taskdef resource="checkstyletask.properties" classpath="checkstyle-5.5-all.jar"/>
<target name="check">
    <checkstyle config="checks.xml" failOnViolation="false">
        <fileset dir="${basedir}" includes="**/*.html"/>
        <formatter type="plain"/>
        <formatter type="xml" toFile="${basedir}/reports/checkstyle-report.xml"/>
    </checkstyle>
</target>

checks.xml:

<module name="Checker">
    <property name="charset" value="UTF-8"/>
    <module name="RegexpMultiline">
        <property name="format" value="\A.+&lt;table&gt;.+&lt;\/table&gt;.+\Z"/>
    </module>
</module>

在 Windows 7 64 位上:

Apache Ant(TM) version 1.8.3 compiled on February 26 2012,
BUILD SUCCESSFUL
Total time: 1 second

在 CentOS 64 位上:

Apache Ant(TM) version 1.8.2 compiled on May 13 2011,
BUILD FAILED
build.xml:8: Unable to create a Checker: cannot initialize module RegexpMultiline - Unable to instantiate RegexpMultiline

谁能给点建议?

谢谢,

【问题讨论】:

    标签: regex ant checkstyle


    【解决方案1】:

    好的,所以只需运行 ant -v 即可显示以下内容:

    parsing buildfile jar:file:/usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml from a zip file
    ...
    [checkstyle] checkstyle version 4.4
    [checkstyle] compiled on Mon December 06 2010, 21:35 GMT
    

    所以失败的原因与其说是操作系统,不如说是Ant安装的版本和配置。

    我认为正在发生的事情是 v4.4 checkstyle 是从

    /usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/antlib.xml
    

    优先于 build.xml 中指定的内容:

    <taskdef resource="checkstyletask.properties" classpath="${basedir}/checkstyle/checkstyle-5.5-all.jar"/>
    

    更新:

    我在 /usr/share/ant/lib/ 中没有找到 checkstyle.jar,但 /usr/share/java/ 中有一个

    不确定 Ant 是如何解决这个问题的,但这最终解决了这个问题:

    yum remove checkstyle4.noarch
    

    现在 Ant 可以免费使用项目中的 .jar 了!

    Others may find this stackoverflow question relevent

    【讨论】:

    • checkstyle 是一个单独的任务,我真的不认为这与 /usr/share/java/ant-1.8.2.jar!/org/apache/tools/ant/ 有任何关系antlib.xml,我会检查 ANT_HOME/lib 是否有任何其他 checkstyle 库。 checkstyle 的版本必须来自一个 checkstyle 库恕我直言。
    • 感谢链接:D 我不知道 lib 目录优先于 taskdef 的类路径属性/声明
    猜你喜欢
    • 2023-03-23
    • 2020-07-28
    • 2019-01-05
    • 2020-05-12
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    相关资源
    最近更新 更多