Today, I ran into a java source file that had a typo in the 'package' statement at the top. The name of the package did not match the name of the directory the file was sitting in (one extra 's' at the end).
To my surprise, javac from 1.6, checkstyle, and pmd all passed the file as OK. The only tool that got around t开发者_运维百科o complaining was javadoc, and only because it was the only file in the package, and a package with no classes in it is a fatal error to javadoc.
Is there some option to javac, or some other command-line tool (preferably with a maven plugin maven) that will squeal about this sort of goof?
I tested this with the latest version of Eclipse and it complains. Eclipse has Maven support.
Well, this seems like an interesting "feature". I fight with such errors regularly once a year. I would guess that PMD, FindBugs or a tool like that will find these errors. However if you say they do not, I can think of only three other options at the moment:
- Use Eclipse compiler from Maven (to compile the sources and see the error). This should be possible although I have never tried it so far.
- Create a custom PMD rule that will check the Java package name and compare it with the directory name.
- Create your own Maven plug-in that will check it. This may not be very easy if you have not develop a Maven plug-in so far.
These are just ideas and should be treated as such.
精彩评论