I just have a test java file(EmployeeTest.java) in folder "C:\Documents and
Settings\pu00118\Desktop\fil
es".
While running PMD via command prompt using the below command, getting error as "File Documents doesn't exist"
C:\Documents and Settings\pu00118\Desktop\PMD>java -cp lib\pmd-4.2.5.jar;lib\jax
en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-util-concurrent.jar;lib\retroweaver-
rt
-2.0.2.jar net.sourceforge.pmd.PMD C:\Documents and Settings\pu00118\Desktop\files text basic
Exception in thread "main" java.lang.RuntimeException: File Documents doesn't
exist
at net.sourceforge.pmd.PMD.collect(PMD.java:846)
at net.sourceforge.pmd.PMD.collectFilesFromOneName(PMD.java:815)
at net.sourceforge.pmd.PMD.doPMD(PMD.java:300)
at net.sourceforge.pmd.PMD.main(PMD.java:415)
Please help me how to resolve this. Thanks in advance
-Balaji
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try to do this instead:
java -cp lib\pmd-4.2.5.jar;lib\jax en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-
util-concurrent.jar;lib\retroweaver-rt -2.0.2.jar net.sourceforge.pmd.PMD
"C:\Docume~1\pu00118\Desktop\files"
Notice the quotes around the location, and the removal of the space. Part of
the reason might be that space at the end. Command prompt would think that's
another argument, so adding the quotes and using ~1 helps eliminate that
issue.
or you can try the following:
Thanks christ66. It worked for me.
Could you please help me in defining a ruleset setup?
I am trying through command prompt for a sample program. To the same how
should I go about it?
like.. where should I keep the files and how am I going to use them to work
with ruleset ?
really thanks alot.
-Balaji
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sure I can help setting up a ruleset file. A ton of information on how to set
it up can be found on this page: http://pmd.sourceforge.net/howtomakearuleset
.html , basically this
file should be in the root directory of your project.
Basically you go to this website: http://pmd.sourceforge.net/rules/index.html and pick out a few nice rules
you want enabled. Then you create the rules.xml file.
If you have a few rules that you want enabled, I can quickly make a rules file
for you.
Since you are running from command line, it should look something like this:
java -cp lib\pmd-4.2.5.jar;lib\jax en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-
util-concurrent.jar;lib\retroweaver-rt -2.0.2.jar net.sourceforge.pmd.PMD
"C:\Docume~1\pu00118\Desktop\files" text %LOCATION_OF_RULES_FILE%
The text part says the format you want the output to be in, and
%LOCATION_OF_RULES_FILE% is the location of the rules.xml file from your
current location.
If you use things like build.xml for ant, it might be easier to create an ant
target to do the running of pmd.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried the way by specifying the myown_ruleset.xml - to avoid empty catch
block by using below code in xml. _
<rule<br>ref="rulesets/basic.xml/EmptyCatchBlock" message="Must handle exceptions">
<priority>2</priority>
</r_ule>
I am not able to integrate the PMD plugin in my RAD7.0. I tried the steps from http://pmd.sourceforge.net/integrations.html#eclipse
This is generally how a ant target looks like. I will explain everything.
First, we must create a target, Ant is similar to make in that they both have
targets which do small script stuff written in java. Essentially the first
part the "taskdef" part is defining where the main method is for pmd. Next, we
can use the value pmd like it's a tag, I picked up a few items from the ant
target page listed below describing what ant is capable of. From there I add
something called a "fileset" which is the list of files I want this pmd target
to evaluate. I want it to "include */.java", so evaluate all java files
located in "java/source/path" but I want it to exclude the file called
"exclude_autogen_files.java" because I want to ignore those files. After that,
that's it, once you save it then you can run "ant pmd" and it should start
running it. Here is the link to the documentations page they wrote which
describes it in more detail along with other items you can add, and examples
of everything. http://pmd.sourceforge.net/ant-task.html
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hey,
Still i am getting this error in eclipse:
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at xmlparsing.DOMParserDemo.main(DOMParserDemo.java:27)
How could i resolve this.Thanks.
Last edit: Andreas Dangel 2015-06-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you get "IllegalArgumentException: InputStream cannot be null" with this code, then "ClassLoader.getSystemResourceAsStream" returned null, because "xml/employee.xml" was not found.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Though i have given -targetjdk 1.7 it still runs in jdk 1.5 mode. why is that and how can i correct it.(jdk 1.5 is default) currently using pmd 4.2.5.
also,
Error while processing file
Error while processing file
java.lang.RuntimeException: org.jaxen.XPathSyntaxException: Expected: ]
at net.sourceforge.pmd.rules.XPathRule.getRuleChainVisits(XPathRule.java:90)
at net.sourceforge.pmd.CommonAbstractRule.usesRuleChain(CommonAbstractRule.java:346)
at net.sourceforge.pmd.AbstractRuleChainVisitor.initialize(AbstractRuleChainVisitor.java:123)
at net.sourceforge.pmd.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:46)
at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:67)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:133)
at net.sourceforge.pmd.PMD.processFile(PMD.java:126)
at net.sourceforge.pmd.PMD.processFile(PMD.java:75)
at net.sourceforge.pmd.PMD.processFile(PMD.java:210)
at net.sourceforge.pmd.PMD$PmdRunnable.call(PMD.java:469)
at net.sourceforge.pmd.PMD$PmdRunnable.call(PMD.java:427)
how to resolve this? your help is appreciated.
Thank you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just have a test java file(EmployeeTest.java) in folder "C:\Documents and
Settings\pu00118\Desktop\fil
es".
While running PMD via command prompt using the below command, getting error as
"File Documents doesn't exist"
C:\Documents and Settings\pu00118\Desktop\PMD>java -cp
lib\pmd-4.2.5.jar;lib\jax
en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-util-concurrent.jar;lib\retroweaver-
rt
-2.0.2.jar net.sourceforge.pmd.PMD C:\Documents and Settings\pu00118\Desktop\files text basic
Exception in thread "main" java.lang.RuntimeException: File Documents doesn't
exist
at net.sourceforge.pmd.PMD.collect(PMD.java:846)
at net.sourceforge.pmd.PMD.collectFilesFromOneName(PMD.java:815)
at net.sourceforge.pmd.PMD.doPMD(PMD.java:300)
at net.sourceforge.pmd.PMD.main(PMD.java:415)
Please help me how to resolve this. Thanks in advance
-Balaji
I found the problem myself.
Solution is: Better dont have the java files on desktop, instead have them
some where in C:\ or ...then it shld work.
Try to do this instead:
java -cp lib\pmd-4.2.5.jar;lib\jax en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-
util-concurrent.jar;lib\retroweaver-rt -2.0.2.jar net.sourceforge.pmd.PMD
"C:\Docume~1\pu00118\Desktop\files"
Notice the quotes around the location, and the removal of the space. Part of
the reason might be that space at the end. Command prompt would think that's
another argument, so adding the quotes and using ~1 helps eliminate that
issue.
or you can try the following:
java -cp lib\pmd-4.2.5.jar;lib\jax en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-
util-concurrent.jar;lib\retroweaver-rt -2.0.2.jar net.sourceforge.pmd.PMD
C:\Docume~1\pu00118\Desktop\files
I believe this other way should work the same.
Thanks christ66. It worked for me.
Could you please help me in defining a ruleset setup?
I am trying through command prompt for a sample program. To the same how
should I go about it?
like.. where should I keep the files and how am I going to use them to work
with ruleset ?
really thanks alot.
-Balaji
Sure I can help setting up a ruleset file. A ton of information on how to set
it up can be found on this page: http://pmd.sourceforge.net/howtomakearuleset
.html , basically this
file should be in the root directory of your project.
Basically you go to this website: http://pmd.sourceforge.net/rules/index.html
and pick out a few nice rules
you want enabled. Then you create the rules.xml file.
If you have a few rules that you want enabled, I can quickly make a rules file
for you.
Since you are running from command line, it should look something like this:
java -cp lib\pmd-4.2.5.jar;lib\jax en-1.1.1.jar;lib\asm-3.1.jar;lib\backport-
util-concurrent.jar;lib\retroweaver-rt -2.0.2.jar net.sourceforge.pmd.PMD
"C:\Docume~1\pu00118\Desktop\files" text %LOCATION_OF_RULES_FILE%
The text part says the format you want the output to be in, and
%LOCATION_OF_RULES_FILE% is the location of the rules.xml file from your
current location.
If you use things like build.xml for ant, it might be easier to create an ant
target to do the running of pmd.
Hi Christ66,
I tried the way by specifying the myown_ruleset.xml - to avoid empty catch
block by using below code in xml. _
<rule<br>ref="rulesets/basic.xml/EmptyCatchBlock"
message="Must handle exceptions">
<priority>2</priority>
</r_ule>
I am not able to integrate the PMD plugin in my RAD7.0. I tried the steps from
http://pmd.sourceforge.net/integrations.html#eclipse
URL provided while connecting is:
http://pmd.sf.net/eclipse
It shows me the error message as : Network connection problems encountered
during search.
Unable to access "http://pmd.sf.net/eclipse".
Unable to access site:
"http://pmd.sf.net/eclipse"
Unable to access site:
"http://pmd.sf.net/eclipse"
Infact for my project, I have to go through build.xml as you specified. If you
have some steps please provide the same. Thanks
-Balaji
Try this website instead:
http://pmd.sourceforge.net/eclipse/
If this one works, post back and I'd probably be best to fix that link in the
page.
That looks like a perfect rule, as long as you have the headers and footers of
the .xml file, you're set!
Build.xml is an easy thing to use!
You first would probably want to create a new target like so:
<target name="pmd" description="This target is for PMD.">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
<pmd
rulesetfiles="RulesFile.xml"
This is generally how a ant target looks like. I will explain everything.
First, we must create a target, Ant is similar to make in that they both have
targets which do small script stuff written in java. Essentially the first
part the "taskdef" part is defining where the main method is for pmd. Next, we
can use the value pmd like it's a tag, I picked up a few items from the ant
target page listed below describing what ant is capable of. From there I add
something called a "fileset" which is the list of files I want this pmd target
to evaluate. I want it to "include */.java", so evaluate all java files
located in "java/source/path" but I want it to exclude the file called
"exclude_autogen_files.java" because I want to ignore those files. After that,
that's it, once you save it then you can run "ant pmd" and it should start
running it. Here is the link to the documentations page they wrote which
describes it in more detail along with other items you can add, and examples
of everything.
http://pmd.sourceforge.net/ant-task.html
hey,
Still i am getting this error in eclipse:
Exception in thread "main" java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at xmlparsing.DOMParserDemo.main(DOMParserDemo.java:27)
How could i resolve this.Thanks.
Last edit: Andreas Dangel 2015-06-10
Hi, can you provide the source code of "DOMParserDemo.java"? That would help...
I assume, you are using something like
(from http://www.javacodegeeks.com/2013/05/parsing-xml-using-dom-sax-and-stax-parser-in-java.html)
If you get "IllegalArgumentException: InputStream cannot be null" with this code, then "ClassLoader.getSystemResourceAsStream" returned null, because "xml/employee.xml" was not found.
Hi,
C:\Users**\pmd-4.2.5\lib>java -jar pmd-4.2.5.jar C:\P*\prideprovider text C:*\bin\rulesets\pmd_rules-v4.xml -tagetjdk 1.7 -debug
In JDK 1.5 mode
Loaded rule UseCollectionIsEmpty
Loaded rule ATG-StringLiteralServiceLocalParameter
Loaded rule BigIntegerInstantiation
Though i have given -targetjdk 1.7 it still runs in jdk 1.5 mode. why is that and how can i correct it.(jdk 1.5 is default) currently using pmd 4.2.5.
also,
Error while processing file
Error while processing file
java.lang.RuntimeException: org.jaxen.XPathSyntaxException: Expected: ]
at net.sourceforge.pmd.rules.XPathRule.getRuleChainVisits(XPathRule.java:90)
at net.sourceforge.pmd.CommonAbstractRule.usesRuleChain(CommonAbstractRule.java:346)
at net.sourceforge.pmd.AbstractRuleChainVisitor.initialize(AbstractRuleChainVisitor.java:123)
at net.sourceforge.pmd.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:46)
at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:67)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:133)
at net.sourceforge.pmd.PMD.processFile(PMD.java:126)
at net.sourceforge.pmd.PMD.processFile(PMD.java:75)
at net.sourceforge.pmd.PMD.processFile(PMD.java:210)
at net.sourceforge.pmd.PMD$PmdRunnable.call(PMD.java:469)
at net.sourceforge.pmd.PMD$PmdRunnable.call(PMD.java:427)
how to resolve this? your help is appreciated.
Thank you
Swati,
bear in mind this forum is dead. All conversation moved to Github 3 years back (see https://sourceforge.net/p/pmd/discussion/188194/thread/fb66e63a63/ )
Moreover, PMD 4.2.5 is over 15 years old. It's no longer supported. PMD is currently at version 7.4.0