{"action":"closed","issue":{"url":"https://api.github.com/repos/checkstyle/checkstyle/issues/712","labels_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/712/labels{/name}","comments_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/712/comments","events_url":"https://api.github.com/repos/checkstyle/checkstyle/issues/712/events","html_url":"https://github.com/checkstyle/checkstyle/issues/712","id":59670121,"number":712,"title":"Custom rule jar/class not found by CheckStyle","user":{"login":"SteffeC","id":11158951,"avatar_url":"https://avatars.githubusercontent.com/u/11158951?v=3","gravatar_id":"","url":"https://api.github.com/users/SteffeC","html_url":"https://github.com/SteffeC","followers_url":"https://api.github.com/users/SteffeC/followers","following_url":"https://api.github.com/users/SteffeC/following{/other_user}","gists_url":"https://api.github.com/users/SteffeC/gists{/gist_id}","starred_url":"https://api.github.com/users/SteffeC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteffeC/subscriptions","organizations_url":"https://api.github.com/users/SteffeC/orgs","repos_url":"https://api.github.com/users/SteffeC/repos","events_url":"https://api.github.com/users/SteffeC/events{/privacy}","received_events_url":"https://api.github.com/users/SteffeC/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-03T16:51:02Z","updated_at":"2015-03-04T22:55:25Z","closed_at":"2015-03-04T22:55:25Z","body":"Hi,\r\n\r\n-I'm trying to create a custom rule below the TreeWalker module in CheckStyle.\r\n\r\n-I'm following the example in http://checkstyle.sourceforge.net/writingchecks.html but can't make CheckStyle find my custom rule class.\r\n\r\n-Using the command in http://checkstyle.sourceforge.net/writingchecks.html#Integrate_your_check :\r\n\r\nC:\\>java -classpath my_rule.jar:checkstyle-6.4-all.jar -c config.xml -r .  (my_rule.jar contains my rule class, config.xml is a subset of the modules in \\checkstyle-6.4-src\\checkstyle-6.4\\config\\checkstyle_checks.xml)\r\n\r\n-Gives the error below:\r\n\r\nUnrecognized option: -c\r\nError: Could not create the Java Virtual Machine.\r\nError: A fatal exception has occurred. Program will exit.\r\n\r\n-If adding \"-jar checkstyle-6.4-all.jar\" to the command:\r\n\r\nC:\\>java -classpath my_rule.jar:checkstyle-6.4-all.jar -jar checkstyle-6.4-all.jar -c config.xml -r .\r\n\r\n-It gives another error:\r\n\r\norg.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -r\r\n        at org.apache.commons.cli.Parser.processOption(Parser.java:363)\r\n        at org.apache.commons.cli.Parser.parse(Parser.java:199)\r\n        at org.apache.commons.cli.Parser.parse(Parser.java:85)\r\n        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:77)\r\nusage: java com.puppycrawl.tools.checkstyle.Main [options] -c <config.xml>\r\n            file...\r\n -c <arg>   The check configuration file to use.\r\n -f <arg>   Sets the output format. (plain|xml). Defaults to plain\r\n -o <arg>   Sets the output file. Defaults to stdout\r\n -p <arg>   Loads the properties file\r\n -v         Print product version and exit\r\n\r\n-If removing \"-r\" from the the command:\r\n\r\nC:\\>java -classpath my_rule.jar:checkstyle-6.4-all.jar -jar checkstyle-6.4-all.jar -c config.xml .\r\n\r\n-The default check works OK:\r\n\r\nStarting audit...\r\nC:\\.\\Test.java:472:17: Name 'TestInvalidMethodName' must match pattern '^[a-z][a-zA-Z0-9]*$'.\r\nC:\\.\\Test.java:499:17: Name 'TestAllErrorsInCombination' must match pattern'^[a-z][a-zA-Z0-9]*$'.\r\nAudit done.\r\n\r\n-The default check also works with the two alternative commands below:\r\n\r\nC:\\>java -classpath checkstyle-6.4-all.jar -jar checkstyle-6.4-all.jar -c config.xml .  (i.e. removed my_rule.jar from classpath)\r\nC:\\>java -jar checkstyle-6.4-all.jar -c config.xml .                                    (i.e. removed all jars from classpath)\r\n\r\n\r\n**** MY PROBLEM IS DESCRIBED BELOW ***\r\n\r\n-My custom rule check doesn't work with the command below:\r\n\r\nC:\\>java -classpath my_rule.jar:checkstyle-6.4-all.jar -jar checkstyle-6.4-all.jar -c my_config.xml . (my_config.xml contains same modules as in config.xml plus my custom rule TestCaseAnnotationCheck class)\r\n\r\n-It looks like the TestCaseAnnotationCheck class is not found on the classpath: \r\n\r\nUnable to create Checker: cannot initialize module TreeWalker - Unable to instantiate com.my.checkstyle.rule.TestCaseAnnotationCheck\r\ncom.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - Unable to instantiate com.my.checkstyle.rule.TestCaseAnnotationCheck\r\n        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:184)\r\n        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:185)\r\n        at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:150)\r\n        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:127)\r\nCaused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate com.my.checkstyle.rule.TestCaseAnnotationCheck\r\n        at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:156)\r\n        at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:182)\r\n        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:185)\r\n        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:163)\r\n        ... 3 more\r\nCaused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate com.my.checkstyle.rule.TestCaseAnnotationCheckCheck\r\n        at com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObjectFactory.java:98)\r\n        at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:153)\r\n        ... 6 more\r\n\r\n-Why is \"Check\" appended on the TestCaseAnnotationCheck class name on this line?\r\nCaused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate com.my.checkstyle.rule.TestCaseAnnotationCheckCheck \r\n\r\n-I get the same error when removing my_rule.jar from the classpath in the command:\r\n\r\nC:\\>java -jar checkstyle-6.4-all.jar -c my_config.xml .\r\n\r\n-It's like CheckStyle can't see my rule jar/class?\r\n\r\n-How do I make CheckStyle find my rule? :)\r\n\r\n-NOTE: My TestCaseAnnotationCheck rule class and my_config.xml works when running it with CheckStyle in Eclipse.\r\n\r\nRegards\r\nSteffeC"}}