You are on page 1of 6

HNG DN CI T V S DNG ECLIPSE 3.0 Nguyn Tng Thy, lp DH02DT, Khoa Cng ngh thng tin, H Nng Lm TP.

HCM Email: nguyentuongthuy@gmail.com Lu : Hng dn di y p dng cho vic ci t Eclipse ngay t u. Trong trng hp nng cp phin bn, cc chi tit c th khc i cht. 1. Ci t Sun Java SDK (J2SE)

2.

Phin bn hin nay ang dng l j2sdk-1_4_2-nb-3_5_1-bin-windows.exe. Sau khi thi hnh file ny th J2SE s c ci vo folder C:\Program Files\j2sdk_nb\j2sdk1.4.2\

Ci t Java 2 Runtime Environment (J2RE)

3.

Phin bn hin nay ang dng l j2re-1_4_2_02windows-i586-p.exe. Sau khi thi hnh file ny th J2RE s c ci vo folder C:\Program Files\j2re1.4.2\

Ci t Eclipse

Phin bn hin nay ang dng l eclipse-SDK-3.0win32.zip. Unzip file ny s c mt folder c tn l eclipse. Hy chuyn folder ny vo a C:, kt qu l eclipse s c ci vo C:\eclipse\ To folder lu d liu khi lm vic vi Eclipse i. Ta nn to folder lm vic a D: ii. to c folder ny, hy to mt shortcut icon cho eclipse screen desktop nh sau: kch phi vo C:\eclipse\eclipse.exe Send To Desktop (create shortcut).

iii.

Ta thm tham s vo shortcut bng cch kch phi vo eclipse shortcut trn screen desktop Properties, textfield Target, ta g thm ng dn. C:\eclipse\eclipse.exe -data D:\<path>\workspace trong <path> l ng dn n subfolder m ta mun workspace trong kch Apply OK.

Mn hnh Welcome ca Eclipse xut hin ta thc thi tp tin eclipse.exe (hay shortcut ca n). Lc ny, chng ta c th lm vic vi Eclipse.

4.

To project v class vi Eclipse

i.

To mt project mi: Chn menu File New Project... Next. Ca s New Java Project xut hin vi yu cu t tn cho project. textfield Project name, ta g vo CoffeeProject, click Next.

ii.

Ca s tip theo cho php ta quy nh nhng thng s cn thit cho project. text field Default output folder, g vo ProjectName/classes, ngha l ta mun quy nh cc file .class s c cha folder ny. Nu khng quy nh iu ny, cc file .class sau khi bin dch t .java s nm cng mt th mc vi cc file .java ny, rt kh quan st.

iii. i.

Click Finish kt thc qu trnh to project mi. To mt class mi: Click chut phi vo project va mi to, chn New Class.

ii.

text field Name ca s New Java Class, ta g vo tn ca class mun to, tn Coffee, click Finish. Class mi c to khng nm trong package no do ta cha quy nh tn ca package text field Package.

iii.

Nh vy ta to c mt class mi, v giao din ca Eclipse s nh sau:

iv.

G vo ca s son tho ca Eclipse ni dung class Coffee nh sau: public class Coffee { private String type; private int weight; // weight in Kilogram private int pricePerKg; public Coffee(String type, int weight, int pricePerKg) { this.type = type; this.weight = weight;

this.pricePerKg = pricePerKg;

public int totalCost() { return weight * pricePerKg; } } i tng Coffee bao gm type l loi ca Coffee, weight l trng ca Coffee c tnh bng k l gam v pricePerKg l gi thnh ca mt k l gam Coffee. Class Coffee c phng thc totalCost() nhm tnh tng gi thnh.

5. i.

Kim th chng trnh vi JUnit Test

To mt TestCase kim th class Coffee: Click chut phi vo CoffeeProject, chn New JUnit Test Case. Mt ca s i hi vic thm gi JUnit vo ng dng xut hin, click Yes tip tc.

ii.

ca s New JUnit Test Case, g vo tn ca TestCase, y l TestCoffee, click Finish.

i.

Tin hnh kim th: u tin, ta g vo class TestCoffee phng thc kim th constructor ca class Coffee. Ni dung lc ny ca TestCoffee nh sau: public class TestCoffee extends TestCase { public void testConstructor() { new Coffee("A", 5, 6000); new Coffee("C", 12, 3500); } }

ii.

Click chut phi vo class TestCoffee, chn Run JUnit Test.

iii.

Thng bo "xanh" ca Eclipse xut hin ngha l constructor ca Coffee vt qua bc kim th.

Lu : C th th JUnit c thng bo "xanh" ( hnh trn) khng xut hin ngay. Bn hy click chn th ny bn cnh th Package Explorer khi cn thit.

iv.

Tip tc, ta g vo TestCoffee phng thc kim th totalCost() ca Coffee. Ni dung ca TestCoffee lc ny nh sau: public class TestCoffee extends TestCase { public void testConstructor() { new Coffee("A", 5, 6000); new Coffee("C", 12, 3500); } public void testTotalCost() { Coffee coffeeA = new Coffee("A", 5, 6000); Assert.assertEquals(coffeeA.totalCost(), 30000); Coffee coffeeC = new Coffee("C", 12, 3500); Assert.assertEquals(coffeeC.totalCost(), 42000);

} }

v. 6.

Sau khi chy JUnit Test, kt qu vn l thng bo "xanh". Vy l phng thc totalCost() ca Coffee cng hot ng tt.

Ci t XMLBuddy plugin son tho file XML

Phin bn hin nay ang dng l xmlbuddy_2.0.10.zip. Unzip file ny s c mt folder c tn l com.objfac.xmleditor_2.0.10. Hy chuyn folder ny vo C:\eclipse\plugins\ Khi ng Eclipse v to mt file XML mi: i. Chn menu File New Other... XML XML Document Next.

ii. iii.

textfield New document name:, t tn file l example Finish. File example.xml s c ni dung sau: <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'> <person> <name>Nguyen Tuong Thuy</name> <phone>8431459</phone> </person>

You might also like