尝试在Eclipse / Juno中为项目运行pmd时,我收到此错误。
An internal error occurred during: "ReviewCode".
Couldn't find the class Can't find resource rulesets/basic.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH. Here's the current classpath: C:\eclipsejuno\eclipse\\plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
任何人都知道如何解决这个问题?
答案 0 :(得分:10)
我也看到了命令行版本的这个问题。在最新版本中,类路径为rulesets/java/basic.xml
似乎他们改变了版本之间的默认路径。您需要手动更新PMD配置中的路径,或更新到最新版本。
答案 1 :(得分:5)
如果" .pmd"文件存在于您的项目中并使用ruleset.xml指示,您可以在上述解决方案之间选择解决问题。
<rule ref="rulesets/basic.xml" />
要
<rule ref="rulesets/java/basic.xml" />
答案 2 :(得分:3)
更改规则集/到规则集/ java /的建议帮助了我,但我还必须更改一条规则:
<rule ref="rulesets/java/controversial.xml/UnusedModifier">
<priority>5</priority>
</rule>
到
<rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
<priority>5</priority>
</rule>
这是我的声纳的PMD配置文件,它适用于PMD-plugin 4.0.2。:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pmd-eclipse"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<rule ref="rulesets/java/basic.xml/UnusedNullCheckInEquals">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/StringInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidRethrowingException">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/ReplaceEnumerationWithIterator">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/optimizations.xml/AvoidArrayLoops">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/ClassCastExceptionWithToArray">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidThrowingNullPointerException">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/UseIndexOfChar">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/BigIntegerInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/FinalFieldCouldBeStatic">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/naming.xml/SuspiciousEqualsMethodName">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/design.xml/InstantiationToGetClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/naming.xml/SuspiciousHashcodeMethodName">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/coupling.xml/LooseCoupling">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/design.xml/SingularField">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/design.xml/CloseResource">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingThrowable">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/basic.xml/UselessOperationOnImmutable">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/UselessOverridingMethod">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedModifier">
<priority>5</priority>
</rule>
<rule ref="rulesets/java/design.xml/PreserveStackTrace">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/optimizations.xml/UseArraysAsList">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/EqualsNull">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/basic.xml/BrokenNullCheck">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/logging-jakarta-commons.xml/UseCorrectExceptionLogging">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/InefficientStringBuffering">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/finalizers.xml/FinalizeOverloaded">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/controversial.xml/DontImportSun">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/imports.xml/DontImportJavaLang">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/design.xml/MissingStaticMethodInNonInstantiatableClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/StringBufferInstantiationWithChar">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/optimizations.xml/UseArrayListInsteadOfVector">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/StringToString">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/SimplifyConditional">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/ReplaceVectorWithList">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/codesize.xml/NcssMethodCount">
<priority>3</priority>
<properties>
<property name="minimum" value="50" />
</properties>
</rule>
<rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/naming.xml/MethodWithSameNameAsEnclosingClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/naming.xml/SuspiciousConstantFieldName">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/codesize.xml/NcssTypeCount">
<priority>3</priority>
<properties>
<property name="minimum" value="800" />
</properties>
</rule>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/IntegerInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/AvoidAssertAsIdentifier">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/UnnecessaryLocalBeforeReturn">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/BooleanInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/UnconditionalIfStatement">
<priority>2</priority>
</rule>
<rule ref="rulesets/java/clone.xml/CloneThrowsCloneNotSupportedException">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/ReplaceHashtableWithMap">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/finalizers.xml/EmptyFinalizer">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/design.xml/IdempotentOperations">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/finalizers.xml/FinalizeDoesNotCallSuperFinalize">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/UseStringBufferLength">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/migrating.xml/AvoidEnumAsIdentifier">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/logging-java.xml/SystemPrintln">
<priority>3</priority>
</rule>
<rule ref="rulesets/java/strings.xml/UselessStringValueOf">
<priority>4</priority>
</rule>
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
<priority>3</priority>
</rule>
</ruleset>
答案 3 :(得分:2)
尝试在Eclipse中更新Maven项目时遇到此错误。对我来说问题是我使用了两个不同的PMD,一个作为Eclipse插件安装,另一个是由Maven从父项目的pom.xml文件下载的。所以我需要做的就是卸载Eclipse的PMD插件,之后就不再出错了。
答案 4 :(得分:0)
在我的情况下,我有自定义的pmdRuleSet.xml,它看起来像:
<rule ref="pmd-rulesets/java/codesize.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="10"/>
</properties>
如果我将“pmd-rulesets”更改为“ruleset”,并且显然是pmdRuleSet.xml中的路径,则会抛出错误,然后一切正常。
答案 5 :(得分:0)
如果您必须面对复杂的项目设置,可以使用此行转换每个.pmd文件
find . -name .pmd -exec sed -i.bak 's/rulesets\/basic.xml/rulesets\/java\/basic.xml/g' {} \;