打开终端,即 terminal,创建新的.bash_profile文件(如果有或创建过此文件,跳过此步骤),输入
touch ~/.bash_profile
打开此文件,输入
open -t ~/.bash_profile
先对环境变量进行解释:
JAVA_HOME: Java的安装路径(决定Java和Javac命令能不能用);
DERBY_HOME: Derby数据库的安装路径;
PATH: 终端读取的路径(决定java -jar $DERBY_HOME/lib/derbyrun.jar server start能不能用);
CLASSPATH:class文件的安装路径(决定java org.apache.derby.tools.ij命令能不能用);
接着继续,在刚打开的文件中添加Derby的环境变量。
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
export DERBY_HOME=/Library/Java/db-derby-10.14.2.0-bin
export PATH=$JAVA_HOME/bin:$DERBY_HOME:.
export CLASSPATH=$DERBY_HOME/lib/derby.jar:$DERBY_HOME/lib/derbyclient.jar:$DERBY_HOME/lib/derbytools.jar:.
按cmd+s保存文件。 运行文件,使其生效,输入
source ~/.bash_profile
查看Derby信息,输入
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)
---------------- 区域设置信息 ------------------
接着,启动ij环境,输入
java org.apache.derby.tools.ij
显示如下内容表示启动成功
ij 版本 10.14
ij>
接着输入
java -jar $DERBY_HOME/lib/derbyrun.jar server start
启动Derby数据库服务器
MacBook:~ apple$ java -jar $DERBY_HOME/lib/derbyrun.jar server start
Fri Oct 05 16:28:00 CST 2018 : 已使用基本服务器安全策略安装了 Security Manager。
Fri Oct 05 16:28:22 CST 2018 : Apache Derby 网络服务器 - 10.14.2.0 - (1828579) 已启动并准备接受端口 1527 上的连接
到这里说明Derby数据库和服务器配置成功啦。