#眉標=Eclipse #大標=OpenSource 整合性開發工具(6) #副標= Java程式風格自動檢查 #作者=文/Doug Chen =======程式======= 程式1檢視新建立的檔案結果 start [doug@runpc testSrc]$ ls Test2.java Test.java [doug@runpc testSrc]$ cat Test2.java import java.io.*; /** This is class level document. */ public class Test2{ /** */ public Test2(){ // do something } public void doSomething(){ System.out.println("LALA~~"); } } [doug@runpc testSrc]$ cat Test.java /** * */ public class Test{ public static void main(String argv[]){} private void xxx(){ } public String getSomeThing(){ return "xxx"; } } =======程式======= =======程式======= 程式2 build.xml <?xml version="1.0" ?> <project name="checkstyle" default="run"> <property environment="env"/> <property name="check.source" value="testSrc" /> <property name="check.config" value= "checkstyle-4.1/sun_checks.xml" /> <property name="xsl" value= "checkstyle-4.1/contrib/checkstyle-simple.xsl" /> <property name="checkstyle.jar" value="checkstyle-4.1/checkstyle-all-4.1.jar" /> <taskdef resource="checkstyletask.properties" classpath="${checkstyle.jar}"/> <target name="checkstyle" description= "Generates a report of code convention violations."> <checkstyle config="${check.config}" failureProperty= "checkstyle.failure" failOnViolation="false"> <formatter type="xml" tofile="checkstyle_report.xml"/> <fileset dir="${check.source}" includes="**/*.java"/> </checkstyle> <style in="checkstyle_report.xml" out= "checkstyle_report.html" style="${xsl}"/> </target> </project> =======程式======= =======程式======= checkstyle-4.1/checkstyle-all-4.1.jar =======程式======= =======程式======= checkstyle-4.1/sun_checks.xml =======程式======= =======程式======= checkstyle-4.1/contrib/checkstyle-simple.xsl =======程式======= =======程式======= checkstyle-4.1/checkstyle-all-4.1.jar =======程式======= =======程式======= 程式3 執行結果 [doug@runpc checkStyle]$ ant checkstyle Buildfile: build.xml checkstyle: [checkstyle] Running Checkstyle 4.1 on 2 files [style] Processing /home/doug/workdoc/java-test/ checkStyle/checkstyle_report.xml to /home/doug/ workdoc/java-test/checkStyle/checkstyle_report.html [style] Loading stylesheet /home/doug/workdoc/java-test/ checkStyle/checkstyle-4.1/contrib/checkstyle-simple.xsl BUILD SUCCESSFUL Total time: 3 seconds =======程式=======