由於JSP會在Run-time時才會作Compile,所以當WebLogic上在deploy程式之後,第一次使用到這個頁面的時候,就會覺得系統緩慢,要等很久畫面才會跳出來,而且如果當時有多個使用者連線進來使用時,同時間要Compile這麼的JSP檔也很耗系統的resource,也會加重對Server Loading,所以如果能在deploy程式的時候就先將JSP compile好,那使用者在第一次使用的時候就不會覺得慢了,Server在服務User的時候,也就不用再耗費額外的資源去做JSP Compile的動作了。

        要作Pre-Compile我知道的有兩種方式,一種是在build file的時候就對JSP作Pre-Compile,另一種只要修改在WAR檔內的weblogic.xml增加一個設定,weblogic就會在deploy時先做Pre-Compile的動作了。

一、先講簡單型的,修改war檔內的WEB-INF/weblogic.xml的設定,增加


.....................
.....................

	
		precompile
		true
	

.....................
.....................


 

如此WebLogic就會在deploy這個WebApplication時,就會對JSP執行Pre-Compile的動作,不過這種方式的缺點就是:
1、Start Weblogic Server的時候會變很長,因為每次restart Server就會做compile。
2、如果JSP的數量太多,也不太適合用這種方法,因為Server Loading太重,很可能Start WebLogic Server 半小時一小時還起不完。
3、如果執行Pre-Compile失敗,那整個WebApplication都不會deploy成功。

二、使用weblogic.appc指令進行pre compile

Examplejava -classpath weblogic.jar;webservices.jar;tools.jar;. weblogic.appc -verbose -forceGeneration -keepgenerated -O query.war

範例如上,紅色部份則改成需要編譯的war檔名稱,執行時appc程式會自動將原本的war解開後pre-compile jsp並將完成compile的class檔案輸出至WEB-INF/classes/jsp_servlet/目錄下後重新再產生成新的 war 檔,另外在執行weblogic.appc需要weblogic.jar;webservices.jar這些jar檔,如果個人電腦有安裝bea weblogic可修改classpath後面jar的指定路徑即可。

有關weblogic.appc 這個指令詳細的參數說明如下請參考
Usage: java weblogic.appc [options]
where options include:
    -help                  Print the standard usage message.
    -version              Print version information.
    -output  <file> Specifies an alternate output archive or directory.
                               If not set, output will be placed in the source archive or directory.
    -forceGeneration  Force generation of EJB and JSP classes.
                               Without this flag the classes may not be regenerated if it is
                               determined to be unnecessary.
    -lineNumbers       Add JSP line numbers to generated class files to aid in debugging.
    -keepgenerated    Keep the generated .java files.
    -verbose              Compile with verbose output.
    -classpath <path> Classpath to use.
    -advanced            Print advanced usage options.