Eclipse3.2和VE插件安裝實戰攻略
早就聽說Eclipse的鼎鼎大名并且領教過了其強大功能,瀏覽了好多關于Eclipse的文章,聽說用SWT,JFace能設計出擁有本地操作系統界面風格的東東,如果在XP上運行,豈不是很讓客戶滿意,近期想要做個桌面系統,, 想試一下. 用Eclipse當然就要裝上再說,這兩天我是吃勁了苦頭..., 下載了很多東西,讀了很多文章,終于調通了,現在給大家分享下.我沒有找到完整的安裝攻略,現在就寫一個最新的.....
建議您先瀏覽下Eclipse網站 http://www.eclipse.org尤其是 Projects 連接, 其中的Eclipse Project, 和 Eclipse Tools Project. Eclipse (Eclipse SDK 最新的是3.2) 是一個平臺,其中的JDT,PDE都是集成在Eclipse下載的,SWT,JFace開發包也是,不用關心太多,有些文章說的很多,反而讓新手迷惑。
Eclipse Tool Project 主要用到Graphical Editor Framework (GEF) Project, EMF, VE 不要急于下載這些東東,我算是吃勁苦頭...... 用Eclipse當然希望用它的可視化編程(Visual Edit Project) 插件. 現在最新的是 VE1.2.0下載頁 http://www.eclipse.org/vep/現看它的下載要求! 因為VE只能和相應版本的GEF,EMF,Eclipse SDK一起工作。
好了,攻略開始.建個下載文件夾. 下載VE(1.2.0) 在同一個頁面的需求里下載 Eclipse SDK 3.2, EMF 2.2.0 , GEF 3.2
下載的文件名稱分別為:
eclipse-SDK-3.2-win32
emf-sdo-runtime-2.2.0
GEF-runtime-3.2
VE-runtime-1.2
VE-SDK-1.2
可以在如下地址下載:
http://download.eclipse.org/tools/ve/downloads/drops/R-1.2-200606280938/index.html
eclipse-SDK-3.2-win32 下載地址:
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.2-200606291905/eclipse-SDK-3.2-win32.zip
emf-sdo-runtime-2.2.0 下載地址:
http://www.eclipse.org/downloads/download.php?file=/tools/emf/downloads/drops/2.2.0/R200606271057/emf-sdo-runtime-2.2.0.zip
GEF-runtime-3.2 下載地址:
http://www.eclipse.org/downloads/download.php?file=/tools/gef/downloads/drops/R-3.2-200606270816/GEF-runtime-3.2.zip
VE-runtime-1.2 下載地址:
http://www.eclipse.org/downloads/download.php?file=/tools/ve/downloads/drops/R-1.2-200606280938/VE-runtime-1.2.zip
VE-SDK-1.2 下載地址:
http://www.eclipse.org/downloads/download.php?file=/tools/ve/downloads/drops/R-1.2-200606280938/VE-SDK-1.2.zip
解壓縮Eclipse SDK 3.2, 把解壓縮里的 eclipse 文件夾拷貝到F:\hongjun 看看里邊的內容,主要是plugins,features 等,解壓縮 emf-sdo-runtime-2.2.0
到F:\hongjun\emf 文件夾, GEF-runtime-3.2到F:\hongjun\gef,VE-runtime-1.2到F:\hongjun\veruntime,,VE-SDK-1.2到F:\hongjun\ve。在eclipse的links文件夾下(我的是在F:\hongjun\eclipse\links)建立一個ve.start文本文件,輸入內容:path=F:\\hongjun\\ve
path=F:\\hongjun\\gef
path=F:\\hongjun\\emf
path=F:\\hongjun\\veruntime
保存完畢。
Eclipse 3.2 需要 JDK1.4.2及以上版本, 所以要先安裝它.JDK的路徑設置就不再說了...\bin, \lib , \jdk1.4.2
由于運行SWT的程序用到本地庫,所以應該導入SWT的原生包 , 運行程序可以自動找到. 這些問題都困擾了我好長時間. 現在啟動F:\hongjun\eclipse.exe,都OK了 eclipse 能自動認出你的JRE.
實戰! 啟動eclipse,看看MyProject 吧,不錯... 界面很迷人! 新建一個項目 file->New->project 出來項目向導, 選擇java project. ->next 輸入project Name: MyProject , Eclipse自動給你建個workspace 工作文件夾,你的項目都存在這里的,F:\hongjun\eclipse\workspace 點擊結束. 一個新項目建成了. 添加SWT ToolKit, 菜單Project->Properties 選擇左側的 Java Build Path 選擇 右側的 Libraries 標簽頁, 點擊 Add Library 按鈕, 選擇 Standard Widget Toolkit(SWT) 點擊 Next , 選上 Include support for JFace library 結束.這樣就可以使用 SWT Jface控件了. 選中你的project MyProject. 選擇新建圖標按鈕, 上端最左側的. 選擇 Visual Class ,點擊Next , Source Folder 是缺省的 project folder, package 填入 lihongjun, Name 填入 Hello , 展開左側的 SWT 選擇 Shell, 勾選上 public static void main(String[] args), Constructors from superclass, Inherited abstract methods. 結束.
Eclipse 自動啟動 VE.... 看看那些窗口... 比較熟悉.. 出現了可視化編輯窗口. 鼠標移到右側的Palette(豎著的那個)把 一個Label,一個Button, 一個TextArea 放到shell上. 選中Label, 在下側的Properties屬性欄可以進行設置, >text 填入Label,選中 Button 在下側的Properties屬性欄可以進行設置, >text 填入Hello everone. 選中 Button 右鍵, events->Add Events . 選擇Mouse ->mouseDoubleClick. 相應的代碼自動產生.也可進行其他的風格設置, 但是如果JDK版本不對則不能操作,有錯。
全部代碼:
package lihongjun;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
public class Hello {
private Shell sShell = null ;
private Label 標簽 = null ;
private Button button = null ;
private Text textArea = null ;
public Hello() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Before this is run, be sure to set up the launch configuration (Arguments->VM Arguments)
* for the correct SWT library path in order to run with the SWT dlls.
* The dlls are located in the SWT plugin jar.
* For example, on Windows the Eclipse SWT 3.1 plugin jar is:
* installation_directory\plugins\org.eclipse.swt.win32_3.1.0.jar
*/
Display display = Display.getDefault();
Hello thisClass = new Hello();
thisClass.createSShell();
thisClass. sShell .open();
while (!thisClass. sShell .isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
* This method initializes sShell
*/
private void createSShell() {
GridLayout gridLayout = new GridLayout();
gridLayout. numColumns = 1;
sShell = new Shell();
sShell .setText( "Shell" );
sShell .setLayout(gridLayout);
sShell .setSize( new Point(300, 200));
標簽 = new Label( sShell , SWT. NONE );
標簽 .setText( "Label" );
Label filler2 = new Label( sShell , SWT. NONE );
button = new Button( sShell , SWT. NONE );
button .setText( "click me!" );
button .addMouseListener( new org.eclipse.swt.events.MouseAdapter() {
public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) {
System. out .println( "mouseDoubleClick()" ); // TODO Auto-generated Event stub mouseDoubleClick()
}
public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
System. out .println( "mouseDown()" ); // TODO Auto-generated Event stub mouseDown()
}
});
Label filler = new Label( sShell , SWT. NONE );
Label filler1 = new Label( sShell , SWT. NONE );
textArea = new Text( sShell , SWT. MULTI | SWT. WRAP | SWT. V_SCROLL );
textArea .setText( "Hello ,everyone!" );
}
}
好了,大功馬上告成. 選擇運行圖標, toolBar 上的綠色按鈕旁邊的黑下箭頭.選擇->run.., 選擇左側的java Application,不一會界面就出來了...., 以后你就可以直接點擊Run圖標,運行這個程序. 點擊Click Me 看看TextArea的變化。