June 22, 2016

Multiple Derby Network Servers on the same Host

Quick Tip 

Suppose you want to start multiple Derby network servers on the same host. They need to be listening on different ports and ideally store their data in different locations. The listings below show Windows batch files to customize how the Derby network server starts.  In this example, Derby will start listening on port 1110 and it will store its data in C:\Data\ns1.

Start port config-ns1.cmd. As the name implies, this batch file configures the Derby network server.  It is the only file which needs editing.

Listing 1: config-ns1.cmd
@echo off 

REM --- START EDITING --- 
set DERBY_HOME=C:\Derby\db-derby-10.12.1.1-bin
set JAVA_HOME=C:\Java\jdk1.8.0_92 
set NS_HOME=C:\Data\ns1
set NS_PORT=1110
set NS_USER=sa
set NS_PASS=sa 
REM --- STOP EDITING --- 

set PATH=%DERBY_HOME%\bin;%PATH%
set DERBY_OPTS=-Dderby.drda.portNumber=%NS_PORT% -Dderby.system.home=%NS_HOME% 

To start the Derby network server, reference config-ns1.cmd then start the server. Listing 2 shows this.

Listing 2: start-ns1.cmd
@echo off 
call config-ns1.cmd
startNetworkServer

To stop the Derby network server, reference config-ns1.cmd then stop the server. Listing 3 shows this.

Listing 3: stop-ns1.cmd
@echo off
call config-ns1.cmd
stopNetworkServer -user %NS_USER% -password %NS_PASS%


Enjoy!

No comments:

Post a Comment