public aspect TraceAspect{
private Logger _logger = Logger.getLogger("trace");
pointcut traceMethods(): execution(* *.*(..))&&!within(TraceAsptect);
before() : traceMethods(){
Signature sig = thisJoinPointStaticPart.getSignature();
_logger.logp(Level.INFO, sig.getDeclaringType().getName(), sig.getName(), "Entering");
}
}
What’s wrong with conventional logging ?
When a new module is added to the system, all of its methods that need logging must be instrumented. Such instrumentation is invasive, causing the tangling of the core concerns with the logging concern. Further, if you ever happen to change the logging toolkit to a different API, you need to revisit every logging statement and modify it.
Consistency is the single most important requirement of logging. It means that if the logging specification requires that certain kinds of operations be logged, then the implementation must log every invocation of those operations. When things go wrong in a system, doubting the logging consistency is probably the last thing you want to do. Missed logging calls can make output hard to understand and sometimes useless. Achieving consistency using conventional logging is a lofty goal, and while systems can attain it initially, it requires continuing vigilance to keep it so. For example, if you add new classes to the system or new methods in existing classes, you must ensure that they implement logging that matches the current logging strategy.
The beauty of AspectJ-based logging
The limitations are not a result of the logging APIs or their implementations; rather, they stem from the fundamental limitations of objectoriented programming, which require embedding the logging invocations in each module. AOP and AspectJ overcome those limitations. AspectJ easily implements the invocation of logging statements from all the log points. The beauty is that you do not need to actually instrument any log points; writing an aspect does it automatically. Further, since there is a central place to control logging operations, you achieve consistency easily.
The most fundamental difference between conventional logging and AspectJbased logging is modularization of the logging concern. Instead of writing modules that implement core concepts in addition to invoking logging operations, with AspectJ you write a few aspects that advise the execution of the operations in the core modules to perform the logging. That way, the core modules do not carry any logging-related code. By modularizing, you separate the logging concern
from the core concerns.
With AspectJ-based logging, the logger aspect separates the core modules and the logger object. Instead of the core modules’ embedding the log() method invocations in their source code, the logger aspect weaves the logging invocations into the core modules when they are needed. AspectJ-based logging reverses the dependency between the core modules and the logger; it is the aspect that encodes how the operations in the core modules are logged instead
of each core module deciding for itself.
Eclipse 運(yùn)行命令行參數(shù)大全
包括英文版本和中文版本兩種的說明, 特別需要值得一提的是那個(gè) -nl 參數(shù), 可以指定程序啟動(dòng)時(shí)所使用的語言. 例如:
eclipse -nl en_US
將啟動(dòng)英文語言, 這個(gè)特性在安裝了國際化語言包以后特別有用, 可以方便的切換各個(gè)語言的版本. 注意 IBM WSAD v5.1 也支持這個(gè)功能.
運(yùn)行 Eclipse
將 Eclipse 驅(qū)動(dòng)程序安裝(解壓縮)到某個(gè)目錄(例如,c:\eclipse)中之后,通過運(yùn)行頂級(jí)安裝目錄中的 Eclipse 可執(zhí)行文件來啟動(dòng)"工作臺(tái)"。在 Windows 系統(tǒng)上,該可執(zhí)行文件稱為 eclipse.exe,而在 Linux 系統(tǒng)上稱為 eclipse。注意:下列討論描述 Windows 系統(tǒng)上的設(shè)置。Linux 上的設(shè)置是相似的。
如果您沒有另行指定,則平臺(tái)將缺省工作區(qū)目錄創(chuàng)建為可執(zhí)行文件的兄弟目錄(例如 c:\eclipse\workspace)。此工作區(qū)目錄用作項(xiàng)目的缺省內(nèi)容區(qū),還用于保存任何必需的元數(shù)據(jù)。要進(jìn)行共享安裝或多工作區(qū)安裝,應(yīng)明確指出工作區(qū)的位置而不是使用缺省值。有兩種控制工作區(qū)位置的方法:使用當(dāng)前工作目錄或使用 -data 命令行自變量。
將工作區(qū)位置設(shè)置為在當(dāng)前工作目錄內(nèi)
在此方案中,工作區(qū)位置將是當(dāng)前工作目錄中稱為 workspace 的目錄。
實(shí)現(xiàn)此目的最容易的方法可能是使用下列步驟來創(chuàng)建快捷方式:
導(dǎo)航到 Windows 資源管理器中的 eclipse.exe 并使用右鍵拖動(dòng)來創(chuàng)建 eclipse.exe 的快捷方式。
編輯快捷方式的屬性,以使啟動(dòng)位置:字段標(biāo)識(shí)工作區(qū)位置的父目錄(例如,c:\users\robert)。
關(guān)閉屬性對(duì)話框并雙擊快捷方式(如果提供的目錄為 c:\users\robert,則工作區(qū)位置將為 c:\users\robert\workspace)。
當(dāng)然,您也可以使用命令提示符(通過將目錄切換為工作區(qū)父目錄然后運(yùn)行 eclipse.exe)來獲得同樣的效果。
使用 -data 設(shè)置工作區(qū)的特定位置
要使用 -data 命令行自變量,只要將 -data your_workspace_location(例如,-data c:\users\robert\myworkspace)添加至快捷方式屬性中的目標(biāo)字段或顯式地將它包括在命令行上。
使用 -vm 設(shè)置 java VM
建議顯式指定在運(yùn)行 Eclipse 時(shí)要使用哪個(gè) Java VM。使用 -vm 命令行自變量(例如,-vm c:\jre\bin\javaw.exe)可以實(shí)現(xiàn)此目的。如果不使用 -vm,則 Eclipse 將使用在 O/S 路徑上找到的一個(gè) Java VM。當(dāng)安裝其它產(chǎn)品時(shí),它們可更改您的路徑,導(dǎo)致在下一次啟動(dòng) Eclipse 時(shí)使用另一 Java VM。
運(yùn)行 Eclipse 中的高級(jí)主題
Eclipse 可執(zhí)行文件及平臺(tái)本身提供了人們感興趣的開發(fā)或調(diào)試 Eclipse 各部件的許多執(zhí)行選項(xiàng)。運(yùn)行 Eclipse 可執(zhí)行文件的一般格式是:
eclipse [platform options] [-vmargs [Java VM arguments]]
Eclipse 啟動(dòng)參數(shù) 命令 描述 原因
-arch architecture
定義 Eclipse 平臺(tái)在其上運(yùn)行的處理器體系結(jié)構(gòu)。Eclipse 平臺(tái)通常使用 Java os.arch 屬性的常用值來計(jì)算最佳設(shè)置。如果在此處指定該項(xiàng),則這是 Eclipse 平臺(tái)使用的值。此處指定的值可作為 BootLoader.getOSArch() 用于插件。示例值有:"x86"、"sparc"、"PA-RISC"和"ppc"。 2.0
-application applicationId
要運(yùn)行的應(yīng)用程序。應(yīng)用程序由向 org.eclipse.core.runtime.applications 擴(kuò)展點(diǎn)提供擴(kuò)展的插件來聲明。通常不需要此自變量。如果指定了此項(xiàng),則該值會(huì)覆蓋配置提供的值。如果不指定此項(xiàng),則會(huì)運(yùn)行"Eclipse 工作臺(tái)"。 1.0
-boot bootJarURL
(建議不使用;用 -configuration 代替;支持 1.0 兼容)。Eclipse 平臺(tái)的引導(dǎo)插件代碼(boot.jar)的位置,表示為 URL。如果指定此項(xiàng),則會(huì)用它來為裝入 Eclipse 平臺(tái)引導(dǎo)程序類裝入器的類裝入器設(shè)置類路徑。僅當(dāng)更改 startup.jar 和 boot.jar 的相對(duì)位置時(shí)才需要它。注意,不允許使用相對(duì) URL。 *1.0
-classloaderproperties [file]
如果指定的話,則使用給定位置處的類裝入器屬性文件來激活平臺(tái)類類裝入器增強(qiáng)。文件自變量可以是文件路徑或 URL。注意,不允許使用相對(duì) URL。單擊此處以獲得更多詳細(xì)信息。 2.0.2
-configuration configurationFileURL
Eclipse 平臺(tái)配置文件的位置,表示為 URL。配置文件確定 Eclipse 平臺(tái)、可用插件集和主要功能部件的位置。注意,不允許使用相對(duì) URL。當(dāng)安裝或更新 Eclipse 平臺(tái)時(shí)配置文件被寫至此位置。 2.0
-consolelog
將 Eclipse 平臺(tái)的錯(cuò)誤日志鏡像到用來運(yùn)行 Eclipse 的控制臺(tái)。與 -debug 組合時(shí)很方便使用。 1.0
-data workspacePath
要運(yùn)行 Eclipse 平臺(tái)的工作區(qū)的路徑。工作區(qū)位置也是項(xiàng)目的缺省位置。相對(duì)于從中啟動(dòng) eclipse 的目錄來解釋相對(duì)路徑。 1.0
-debug [optionsFile]
將平臺(tái)置于調(diào)試方式,并從給定位置處的文件裝入調(diào)試選項(xiàng)(如果指定的話)。此文件指示哪些調(diào)試點(diǎn)可用于插件以及是否已啟用它們。如果未給出文件位置,則平臺(tái)在啟動(dòng) eclipse 的目錄中查找稱為".options"的文件。URL 和文件系統(tǒng)路徑都可作為文件位置。 1.0
-dev [classpathEntries]
將平臺(tái)置于開發(fā)方式。將可選類路徑條目(用逗號(hào)分隔的列表)添加至每個(gè)插件的運(yùn)行時(shí)類路徑。例如,當(dāng)工作區(qū)包含要開發(fā)的插件時(shí),指定 -dev bin 會(huì)為每個(gè)插件項(xiàng)目的名為 bin 的目錄添加類路徑條目,允許在其中存儲(chǔ)最新生成的類文件。除去了冗余或不存在的類路徑條目。 1.0
-endsplash params
用于在 Eclipse 平臺(tái)啟動(dòng)并運(yùn)行時(shí)關(guān)閉閃屏的內(nèi)部選項(xiàng)。此選項(xiàng)在閃屏處理鏈中不同的位置有不同的語法和語義。 2.0
-feature featureId
主要功能部件的標(biāo)識(shí)。主要功能部件為 Eclipse 的已啟動(dòng)實(shí)例提供了產(chǎn)品個(gè)性,并確定使用的產(chǎn)品定制信息。 2.0
-keyring keyringFilePath
磁盤上授權(quán)數(shù)據(jù)庫(或"密鑰環(huán)"文件)的位置。此自變量必須與 -password 選項(xiàng)配合使用。相對(duì)于從中啟動(dòng) eclipse 的目錄來解釋相對(duì)路徑。 1.0
-nl locale
定義 Eclipse 平臺(tái)在其上運(yùn)行的語言環(huán)境的名稱。Eclipse 平臺(tái)通常自動(dòng)計(jì)算最佳設(shè)置。如果在此處指定該項(xiàng),則這是 Eclipse 平臺(tái)使用的值。此處指定的值可作為 BootLoader.getNL() 用于插件。示例值有:"en_US"和"fr_FR_EURO"。 2.0
-nolazyregistrycacheloading
取消激活裝入優(yōu)化的平臺(tái)插件注冊(cè)表高速緩存。缺省情況下,僅當(dāng)需要時(shí)才從注冊(cè)表高速緩存(可用時(shí))中裝入擴(kuò)展的配置元素,以減少內(nèi)存占用。此選項(xiàng)將在啟動(dòng)時(shí)強(qiáng)制完全裝入注冊(cè)表高速緩存。 2.1
-noregistrycache
繞過讀寫內(nèi)部插件注冊(cè)表高速緩存文件。 2.0
-nosplash
運(yùn)行平臺(tái)而不顯示閃屏。 1.0
-os operatingSystem
定義 Eclipse 平臺(tái)在其上運(yùn)行的操作系統(tǒng)。Eclipse 平臺(tái)通常使用 Java os.name 屬性的常用值來計(jì)算最佳設(shè)置。如果在此處指定該項(xiàng),則這是 Eclipse 平臺(tái)使用的值。此處指定的值可作為 BootLoader.getOS() 用于插件,并用于解析插件清單文件中提及的路徑中 $os$ 變量的出現(xiàn)。示例值有:"win32"、"linux"、"hpux"、"solaris"和"aix"。 1.0
-password password
授權(quán)數(shù)據(jù)庫的密碼。與 -keyring 選項(xiàng)配合使用。 1.0
-perspective perspectiveId
啟動(dòng)時(shí)要在活動(dòng)工作臺(tái)窗口中打開的透視圖。如果沒有指定該參數(shù),則將打開關(guān)閉時(shí)活動(dòng)的透視圖。 1.0
-plugincustomization propertiesFile
包含插件首選項(xiàng)缺省設(shè)置的屬性文件的位置。這些缺省設(shè)置覆蓋在主要功能部件中指定的缺省設(shè)置。相對(duì)于從中啟動(dòng) eclipse 的目錄來解釋相對(duì)路徑。 2.0
-plugins pluginsFileURL
(建議不使用;用 -configuration 代替;支持 1.0 兼容)。 指定 Eclipse 平臺(tái)查找插件的文件的位置,表示為 URL。該文件為屬性文件格式,其中鍵是任意用戶定義名稱,值是指向 plugin.xml 文件的顯式路徑或指向包含插件的目錄的路徑的用逗號(hào)分隔的列表。注意,不允許使用相對(duì) URL。如果指定此項(xiàng),則此選項(xiàng)會(huì)導(dǎo)致創(chuàng)建適當(dāng)?shù)呐R時(shí)配置。 *1.0
-refresh
啟動(dòng)時(shí)執(zhí)行工作區(qū)的全局刷新的選項(xiàng)。這將使從上次平臺(tái)運(yùn)行以來在文件系統(tǒng)中所做的任何更改一致。 1.0
-showlocation
用于在窗口標(biāo)題欄中顯示工作區(qū)的位置的選項(xiàng)。在發(fā)行版 2.0 中,此選項(xiàng)僅與 -data 命令行自變量一起使用。 2.0
-showsplash params
用于顯示閃屏(由可執(zhí)行的 Eclipse 平臺(tái)啟動(dòng)器執(zhí)行)的內(nèi)部選項(xiàng)。此選項(xiàng)在閃屏處理鏈中不同的位置有不同的語法和語義。 2.0
-vm vmPath
要用來運(yùn)行 Eclipse 平臺(tái)的"Java 運(yùn)行時(shí)環(huán)境"(JRE)的位置。如果不指定此項(xiàng),則 JRE 位于 jre(它是 Eclipse 可執(zhí)行文件的兄弟目錄)。相對(duì)于從中啟動(dòng) eclipse 的目錄來解釋相對(duì)路徑。 1.0
-ws windowSystem
定義 Eclipse 平臺(tái)在其上運(yùn)行的 Windows 系統(tǒng)。Eclipse 平臺(tái)通常使用 Java os.name 屬性的常用值來計(jì)算最佳設(shè)置。如果在此處指定該項(xiàng),則這是 Eclipse 平臺(tái)使用的值。此處指定的值可作為 BootLoader.getWS() 用于插件、用于配置 SWT 以及用于解析插件清單文件中提及的路徑中 $ws$ 變量的出現(xiàn)。示例值有:"win32"、"motif"和"gtk"。 1.0
將 -vmargs 條目后面的所有自變量(但不包括 -vmargs)作為虛擬機(jī)自變量(即,在要運(yùn)行的類的前面)直接傳遞到所指示的 Java VM。注意:如果 Eclipse 啟動(dòng)在 Java vm 自變量(-vmargs)之后提供的自變量(例如,-data),則 Eclipse 將不會(huì)啟動(dòng)并且您將接收到"JVM 已終止。出口代碼為 1"的錯(cuò)誤。
在不同的 VM 上運(yùn)行
在 J9 上運(yùn)行 Eclipse
當(dāng)在 J9 版本 1.5 上運(yùn)行 Eclipse 時(shí),建議使用以下 VM 選項(xiàng):
eclipse.exe [eclipse arguments] -vm path_to_j9w.exe -vmargs -ms:32 -mm:2048 -mo:32768 -moi:32768 -mca:32 -mco:128 -mx:2000000
當(dāng)在 J9 版本 2.0 上運(yùn)行 Eclipse 時(shí),J9W 選擇的缺省自變量應(yīng)為合適的選項(xiàng)。但是,要覆蓋 Eclipse 可執(zhí)行文件以內(nèi)部方式自動(dòng)設(shè)置的參數(shù),必須指定 -vmargs 不帶任何參數(shù),如下所示:
eclipse.exe [eclipse arguments] -vm path_to_j9w.exe -vmargs
有關(guān)進(jìn)一步信息,參考 J9 VM 文檔和幫助。
在 IBM Developer Kit, Java(TM) Technology Edition VM 上運(yùn)行 Eclipse
IBM Developer Kit, Java(TM) Technology Edition 1.3 Linux 的缺省 VM 設(shè)置適合進(jìn)行初期研究工作,但在進(jìn)行大型開發(fā)時(shí)是不夠的。對(duì)于大型開發(fā),應(yīng)修改 VM 自變量以使有更多的堆可用。例如,下列設(shè)置將允許 Java 堆增大為 256MB: