Eclipse怎么搭建Ruby環(huán)境呢?最近想學(xué)習(xí)Ruby,想在Eclipse中搭建一個(gè)Ruby開(kāi)發(fā)環(huán)境,在網(wǎng)上整理了一些資料,下面小編就給大家?guī)?lái)Eclipse怎么搭建Ruby環(huán)境 Eclipse下搭建Ruby環(huán)境方法,一起學(xué)習(xí)吧。
Eclipse搭建Ruby開(kāi)發(fā)環(huán)境
1.環(huán)境搭建
1.1JDK安裝配置
1)點(diǎn)擊下面網(wǎng)址下載JDK5.0:
http://java.sun.com/javase/downloads/index_jdk5.jsp
2)下載完成后,雙擊圖標(biāo)進(jìn)行安裝,安裝過(guò)程中選擇安裝目錄(例如:C:jdk1.5.0_11)
3)配置JDK環(huán)境變量:
(1)右擊"我的電腦",點(diǎn)擊"屬性",選擇"高級(jí)"選項(xiàng)卡,點(diǎn)擊"環(huán)境變量",出現(xiàn)環(huán)境變量屬性窗口如下:
圖1
(2)建第一個(gè)系統(tǒng)變量:JAVA_HOME值:C:jdk1.5.0_11
圖2
(3)建第二個(gè)系統(tǒng)變量:CLASSPATH值:.;%JAVA_HOME%lib
圖3
(4)修改系統(tǒng)變量PATH值,在原有值前加上%JAVA_HOME%bin;
圖4
備注:
必須加到PATH值最前面;
(5)測(cè)試j2sdk的安裝與環(huán)境變量設(shè)置是否正確:
在命令提示符中輸入:java-version
圖5
1.2Eclipse安裝配置
1)下載Eclipse及插件:
Eclipse3.2.2下載地址:
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.2.2-200702121330/eclipse-SDK-3.2.2-win32.zip
Eclipse3.2.2多國(guó)語(yǔ)言包下載地址:
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/L-3.2.1_Language_Packs-200609210945/NLpack1-eclipse-SDK-3.2.1-win32.zip
RDT(RubyDevelopmentTool)下載地址:
http://downloads.sourceforge.net/rubyeclipse/org.rubypeople.rdt-0.8.0.604272100PRD.zip
2.配置Eclipse:
(1)將下載的eclipse-SDK-3.2.2-win32.zip解壓到C:eclipse
(2)將下載的多國(guó)語(yǔ)言包解壓到C:eclipselanguage
注意:
language目錄下有一個(gè)eclipse子目錄,然后才是features、plugins目錄;
(3)建立語(yǔ)言包的link文件:在C:eclipse目錄下新建一個(gè)目錄并取名為links,在該目錄中新建一個(gè)文本文件并取名為language.link(擴(kuò)展名必須為.link),然后在language.link文件中加一行文字:
path=C:eclipselanguage
目錄結(jié)構(gòu)如下:
圖6
(4)將下載的RDT文件解壓到C:eclipse對(duì)應(yīng)的features、plugins目錄;
(5)運(yùn)行C:eclipseeclipse.exe,界面如下:
圖7
2、Ruby及插件安裝配置
a)下載RUBY及插件
ruby下載地址:
http://rubyforge.org/frs/download.php/18566/ruby186-25.exe
ruby-dbi插件下載地址:
http://rubyforge.org/frs/download.php/12368/dbi-0.1.1.tar.gz
ruby-oci8插件下載地址:
http://rubyforge.org/frs/download.php/16630/ruby-oci8-1.0.0-rc1.tar.gz
http://rubyforge.org/frs/download.php/16631/ruby-oci8-1.0.0-rc1-mswin32.rb
watir下載地址:
http://rubyforge.org/frs/download.php/5677/watir-1.4.1.exe
watir中文補(bǔ)丁下載地址:
http://rubyforge.org/tracker/download.php/104/489/3232/440/watir-cn.zip
b)安裝配置:
i.下載Ruby后,雙擊進(jìn)行安裝,安裝過(guò)程中選擇安裝目錄(例如:C:ruby);
ii.下載Watir后,雙擊進(jìn)行安裝,安裝過(guò)程中選擇安裝目錄(例如:C:ProgramFilesWatir)
iii.下載dbi-0.1.1.tar.gz后,解壓后運(yùn)行目錄下的setup.rb;
iv.下載ruby-oci8-1.0.0-rc1.tar.gz后,解壓后運(yùn)行目錄下的setup.rb;
v.運(yùn)行ruby-oci8-1.0.0-rc1-mswin32.rb;
vi.將watir-cn.rb拷貝到C:rubylibrubysite_ruby1.8目錄;
c)配置Ruby解釋器
(1)打開(kāi)Eclipse主界面,右擊"我的電腦",點(diǎn)擊"窗口",選擇"首選項(xiàng)",進(jìn)入對(duì)話(huà)框中"Ruby>InstalledInterpreters"入口,如下:
圖8
(2)點(diǎn)擊"add",在對(duì)話(huà)框中輸入信息后,如下:
圖9
(3)點(diǎn)擊"確定",完成配置。
2.Ruby操作Oracle
2.1connect
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
dbh.disconnect
備注:
HOST:oracle服務(wù)器IP或主機(jī)名
NAME:登錄Oracle的用戶(hù)名
PASSWORD:登錄Oracle的密碼
2.2CreateTable
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
dbh.do("CREATETABLEstates(
idCHAR(2)PRIMARYKEY,
nameVARCHAR2(15)NOTNULL,
capitalVARCHAR2(25)NOTNULL)")
dbh.disconnect
2.3Insert
方法一:
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
sqlInsert="INSERTINTOstates(id,name,capital)
VALUES('AL','Alabama','Birmingham')"
dbh.commit
dbh.disconnect
方法二:
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
sqlInsert="INSERTINTOstates(id,name,capital)
VALUES(?,?,?)"
dbh.do(sqlInsert,"AL","Alabama","Birmingham")#參數(shù)化
dbh.do(sqlInsert,"AZ","Arizona","Phoenix")
dbh.commit
dbh.disconnect
2.4Update
方法一:
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
dbh.do("UPDATEstatesSETid='ME'WHEREname='Maine'")
dbh.commit
dbh.disconnect
方法二:
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
sqlCapitalsUpdate="UPDATEstatesSETcapital=?WHEREid=?"
dbh.do(sqlCapitalsUpdate,"Montgomery","AL")#參數(shù)化
dbh.do(sqlCapitalsUpdate,"Harrisburg","PA")#參數(shù)化
dbh.do("UPDATEstatesSETid='ME'WHEREname='Maine'")
dbh.commit
dbh.disconnect
2.5Select
require'dbi'
dbh=DBI.connect('DBI:OCI8:HOST','NAME','PASSWORD')
rs=dbh.prepare('SELECT*FROMstates')
rs.execute
whilersRow=rs.fetchdo
prsRow#輸出結(jié)果
#Alternativeoutput:putsrsRow
#Alternativeoutput:pprsRow
end
rs.finish
dbh.disconnect
備注:
rsRow[Column][Row]:查詢(xún)結(jié)果的地Column行第Row列值
如:rsRow[0][0]
rsRow[0][0]:第1行第1列值,值為:AL
輸出結(jié)果如下:
圖10