WhileLoopsMustUseBracesRule.java:3: error: cannot access ImmutableLanguage
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
^
class file for net.sourceforge.pmd.lang.rule.ImmutableLanguage not found
1 error
NOTE: That arrow is actually aiming at the "class" part not "public"
So I am trying to figure out how to compile this without errors so that my custom ruleset will recognize this as a valid class. (currently it says "Couldn't find the class WhileLoopsMustUseBracesRule").
Any help is appreciated, thanks!
Last edit: Jimmy Philps 2015-07-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One last issue is that when I run that javac -cp lib/* WhileLoopsMustUseBracesRule.java I get this error message:
javac: invalid flag: lib/asm-5.0.3.jar
Usage: javac <options>
use -help for a list of possible options</options>
asm-5.0.3.jar is the second item in that lib subdirectory, so I think that it is reading in the subsequent filenames in lib as additional parameters for some reason...
So I guess what I am asking is, is lib/* the proper way to include multiple <options> files? </options>
Also I realize this is more of a java compiling question so I apologize if it is wasting your time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I did this steps, but when I run this script I got a new error:
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:1: error: package net.sourceforge.pmd.lang.java.rule does not exist
import net.sourceforge.pmd.lang.java.rule.;
^
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:2: error: package net.sourceforge.pmd.lang.java.ast does not exist
import net.sourceforge.pmd.lang.java.ast.;
^
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:4: error: cannot find symbol
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
^
symbol: class AbstractJavaRule
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:5: error: cannot find symbol
public Object visit(ASTWhileStatement node, Object data) {
^
symbol: class ASTWhileStatement
location: class WhileLoopsMustUseBracesRule
4 errors
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
sorry for the late response.
I've now created two sample projects, of how to build a custom rule:
See https://github.com/pmd/pmd-examples
Let me know, how we can improve such guides.
Regards,
Andreas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to follow the instructions for making a custom rule via Java (not XPath). The end result is as follows:
import net.sourceforge.pmd.lang.java.rule.*;
import net.sourceforge.pmd.lang.java.ast.*;
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
public Object visit(ASTWhileStatement node, Object data) {
System.out.println("hello world");
return data;
}
}
So when I try to compile using the following command:
javac -cp lib/pmd-java-5.3.2.jar WhileLoopsMustUseBracesRule.java
The error message I receive is as follows:
WhileLoopsMustUseBracesRule.java:3: error: cannot access ImmutableLanguage
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
^
class file for net.sourceforge.pmd.lang.rule.ImmutableLanguage not found
1 error
NOTE: That arrow is actually aiming at the "class" part not "public"
So I am trying to figure out how to compile this without errors so that my custom ruleset will recognize this as a valid class. (currently it says "Couldn't find the class WhileLoopsMustUseBracesRule").
Any help is appreciated, thanks!
Last edit: Jimmy Philps 2015-07-09
You'll need to add all jar files to the classpath while compiling. You can do this simply by this command:
javac -cp lib/* WhileLoopsMustUseBracesRule.javaUpdate: See below
Then it should work :)
Last edit: Andreas Dangel 2018-02-08
Correction: the asterisk (*) must be in quotes, otherwise your shell will expand it, so the correct command is:
javac -cp 'lib/*' WhileLoopsMustUseBracesRule.java
Awesome, thanks for the response!
One last issue is that when I run that javac -cp lib/* WhileLoopsMustUseBracesRule.java I get this error message:
javac: invalid flag: lib/asm-5.0.3.jar
Usage: javac <options>
use -help for a list of possible options</options>
asm-5.0.3.jar is the second item in that lib subdirectory, so I think that it is reading in the subsequent filenames in lib as additional parameters for some reason...
So I guess what I am asking is, is lib/* the proper way to include multiple <options> files? </options>
Also I realize this is more of a java compiling question so I apologize if it is wasting your time.
Actually, I have resolved that issue. I just needed to escape the asterisk. So I used the following instead:
javac -cp lib/\* WhileLoopsMustUseBracesRule.java
But thanks for all your help!
Last edit: Jimmy Philps 2015-07-09
Hi, I did this steps, but when I run this script I got a new error:
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:1: error: package net.sourceforge.pmd.lang.java.rule does not exist
import net.sourceforge.pmd.lang.java.rule.;
^
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:2: error: package net.sourceforge.pmd.lang.java.ast does not exist
import net.sourceforge.pmd.lang.java.ast.;
^
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:4: error: cannot find symbol
public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
^
symbol: class AbstractJavaRule
C:\Ph.D\IdentifierName\Workspace\Azadeh\src\WhileLoopsMustUseBracesRule.java:5: error: cannot find symbol
public Object visit(ASTWhileStatement node, Object data) {
^
symbol: class ASTWhileStatement
location: class WhileLoopsMustUseBracesRule
4 errors
@Azadeh, Were you able to get rid of these errors? I'm getting the same
Hi all,
sorry for the late response.
I've now created two sample projects, of how to build a custom rule:
See https://github.com/pmd/pmd-examples
Let me know, how we can improve such guides.
Regards,
Andreas