# Mac OS環境下配置環境變數(以配置Derby資料庫為例)
Mac OS配置環境方法:
1、開啟終端(即terminal)。 2、輸入touch ~/.bash_profile建立新的.bash_profile檔案(如果有或建立過此檔案,跳過此步驟)。 3、輸入open -t ~/.bash_profile開啟此檔案。 4、按照export XXXX=“/xxx/xxx/xxx"的格式編輯(如:export CLASSPATH=“./JAVA_HOME/lib;$JAVA_HOME/jre/lib”。 5、按cmd+s儲存檔案。 6、輸入source ~/.bash_profile執行檔案,使其生效。 7、可以通過輸入echo $XXXX來驗證是否生效(如:輸入echo $CLASSPATH,如果出現/lib/derby.jar:/lib/derbytools.jar:.則說明配置成功)
以配置Derby資料庫為例:
1、開啟終端(即terminal)。 2、輸入touch ~/.bash_profile建立新的.bash_profile檔案(如果有或建立過此檔案,跳過此步驟)。 3、輸入open -t ~/.bash_profile開啟此檔案。 4、輸入Derby的環境變數。 在我這裡是: export DERBY_INSTALL="/Library/Java/db-derby-10.14.2.0-bin"
export CLASSPATH=“DERBY_INSTALL/lib/derbytools.jar:.”
export DERBY_HOME="/Library/Java/db-derby-10.14.2.0-bin" 5、按cmd+s儲存檔案。 6、輸入source ~/.bash_profile執行檔案,使其生效。 7、分別輸入 echo $ DERBY_INSTALL echo $ CLASSPATH echo $ PATH 如果分別彈出 $ DERBY_INSTALL $ CLASSPATH $ DERBY_HOME 則說明檔案生效 8、輸入java org.apache.derby.tools.sysinfo 如果彈出以下內容則說明配置成功
------------------ Java 資訊 ------------------
Java Version: 10.0.2
Java Vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre
Java classpath: /Users/me/src:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derby.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derby.war:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_cs.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_de_DE.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_es.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_fr.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_hu.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_it.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_ja_JP.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_ko_KR.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_pl.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_pt_BR.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_ru.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_zh_CN.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyLocale_zh_TW.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyclient.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbynet.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyoptionaltools.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbyrun.jar:/Users/me/sw/z/db-derby-10.14.2.0-bin/lib/derbytools.jar:/Users/me/sw/db2jcc/lib/db2jcc.jar:/Users/me/sw/db2jcc/lib/db2jcc_license_c.jar:/Users/me/sw/mysql/connectorj/mysql-connector-java-5.0.7/mysql-connector-java-5.0.7-bin.jar:/Users/me/sw/demo/jdbc.concurrent/jars/jdbc-concurrent.jar:/Users/me/sw/demo/tableFunctionWhitePaper/jars/vtis-example.jar
OS name: Mac OS X
OS architecture: x64_64
OS version: 10.11.5
Java user name: me
Java user home: /Users/me
Java user dir: /Users/me/derby/branches/10.14
java.specification.name: Java Platform API Specification
java.specification.version: 1.8
java.runtime.version: 1.8.0-b132
--------- Derby 資訊 --------
[/Library/Java/db-derby-10.14.2.0-bin/lib/derby.jar] 10.14.2.0 - (1828579)
[/Library/Java/db-derby-10.14.2.0-bin/lib/derbytools.jar] 10.14.2.0 - (1828579)
------------------------------------------------------
----------------- 區域設定資訊 -----------------
------------------------------------------------------
------------------------------------------------------
9、接著輸入java org.apache.derby.tools.ij啟動ij環境
Macbook:~user$ java org.apache.derby.tools.ij
ij 版本 10.14
ij>
10、到這裡就可以輸入Derby資料庫指令啦。