{"id":1023,"date":"2016-09-15T13:00:14","date_gmt":"2016-09-15T11:00:14","guid":{"rendered":"http:\/\/www.pellissier.co.za\/hermien\/?p=1023"},"modified":"2019-09-09T10:50:20","modified_gmt":"2019-09-09T08:50:20","slug":"running-apache-derby-as-a-windows-service","status":"publish","type":"post","link":"https:\/\/www.pellissier.co.za\/hermien\/?p=1023","title":{"rendered":"Running Apache Derby as a Windows Service"},"content":{"rendered":"<p>I have only ever used Apache Derby (or Java DB as the version distributed with the JDK is called) in its embedded mode. But then a friend recently told me that he is running it not only in client\/server mode but also as a Windows service! This post is about how I recreated that setup with instructions from him.<\/p>\n<p>Let me first list all the tools that I used:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk8-downloads-2133151.html\" target=\"_blank\">JDK 8<\/a> (I have update 101 installed) &#8211; this includes Java DB<\/li>\n<li><a href=\"https:\/\/commons.apache.org\/proper\/commons-daemon\/procrun.html\" target=\"_blank\">Procrun<\/a> from Apache Commons Daemon<\/li>\n<li><a href=\"https:\/\/netbeans.org\/\">NetBeans<\/a> (optional) as a user friendly way to interact with the database, to make sure that it is up and running<\/li>\n<\/ul>\n<h4>Manually Starting Client\/Server Mode<\/h4>\n<p>First of all, it is a good idea to enable some kind of authentication. To do this, create a file called derby.properties in the %JDK_HOME%\\db\\bin folder with these properties (obviously specifying more secure passwords for real world uses):<\/p>\n<pre class=\"toolbar-overlay:false wrap:true lang:default decode:true \">derby.connection.requireAuthentication=true\nderby.authentication.provider=BUILTIN\n\n# Users definition\nderby.user.sysdba=masterkey\nderby.user.derbyuser1=password1\nderby.user.derbyuser2=password2<\/pre>\n<p>Now we can start up the server from the command line:<\/p>\n<p>[crayon lang=&#8221;text&#8221; wraplines=&#8221;true&#8221;]java -cp %DERBY_HOME%\\lib\\derbynet.jar org.apache.derby.drda.NetworkServerControl start[\/crayon]<\/p>\n<h4>Creating the Database<\/h4>\n<p>Read the documentation <a href=\"https:\/\/db.apache.org\/derby\/docs\/10.2\/workingwithderby\/twwdactivity1.html\" target=\"_blank\">here<\/a> for more info about how to create a new database. Keep in mind that if you are using the Java DB installed with the JDK, which by default lives in C:\\Program Files, you will need to start up ij from a command prompt with administrator access. If you don&#8217;t, it won&#8217;t have permissions to create files in the Program Files folder, and you will see an exception when you execute the commit command.<\/p>\n<p>If you are following this step by step, go ahead and create yourself a database now. I called mine firstdb just like in the documentation.<\/p>\n<p>Disconnect and exit from ij before trying to connect from another application such as NetBeans.<\/p>\n<h4>Connecting from NetBeans<\/h4>\n<p>After exiting ij, I could successfully connect to firstdb from NetBeans:<\/p>\n<figure id=\"attachment_1038\" aria-describedby=\"caption-attachment-1038\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.pellissier.co.za\/hermien\/wp-content\/uploads\/sites\/2\/2016\/09\/nb-properties1.png\"><img loading=\"lazy\" src=\"http:\/\/www.pellissier.co.za\/hermien\/wp-content\/uploads\/sites\/2\/2016\/09\/nb-properties1.png\" alt=\"Connection Properties\" width=\"560\" height=\"458\" class=\"size-full wp-image-1038\" srcset=\"https:\/\/www.pellissier.co.za\/hermien\/wp-content\/uploads\/sites\/2\/2016\/09\/nb-properties1.png 560w, https:\/\/www.pellissier.co.za\/hermien\/wp-content\/uploads\/sites\/2\/2016\/09\/nb-properties1-300x245.png 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/a><figcaption id=\"caption-attachment-1038\" class=\"wp-caption-text\">Connection Properties<\/figcaption><\/figure>\n<h4>Running as a Service with Procrun<\/h4>\n<p>In order to use Procrun, you will need to <a href=\"http:\/\/www.apache.org\/dist\/commons\/daemon\/binaries\/windows\/\" target=\"_blank\">download the native binaries<\/a> for Windows. (You can also get there by clicking on the Native binaries link on the <a href=\"https:\/\/commons.apache.org\/proper\/commons-daemon\/procrun.html\" target=\"_blank\">Procrun page<\/a>.)<\/p>\n<p>Create a new folder %JDK_HOME%\\db\\Windows_Service, and extract prunsrv.exe there. Also create two files (obviously pay attention to paths that may be different on your system):<\/p>\n<p>Install_Service.cmd containing:<\/p>\n<pre class=\"toolbar-overlay:false wrap:true lang:default decode:true \">prunsrv \/\/IS\/\/DerbyService --DisplayName=\"Derby Service\" --Install=\"C:\\Program Files\\Java\\jdk1.8.0_101\\db\\Windows_Service\\prunsrv.exe\" --Jvm=auto --StartMode=jvm --StopMode=jvm --Classpath=\"C:\/Program Files\/Java\/jdk1.8.0_101\/db\/lib\/derbynet.jar\" --StartClass=org.apache.derby.drda.NetworkServerControl --StartParams=start --StopClass=org.apache.derby.drda.NetworkServerControl --StopParams=shutdown<\/pre>\n<p>Uninstall_Service.cmd containing:<\/p>\n<pre class=\"toolbar-overlay:false wrap:true lang:default decode:true \">prunsrv \/\/DS\/\/DerbyService<\/pre>\n<p>These two files can then be executed to install or uninstall the service. Once the service is installed, start it up in the usual way.<\/p>\n<p>After starting it, the database no longer existed. This is because the working folder was different, and hence the location where the data is read is different. So I just created the new database one last time, by adding the create=true property to the connection in NetBeans.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have only ever used Apache Derby (or Java DB as the version distributed with the JDK is called) in its embedded mode. But then a friend recently told me that he is running it not only in client\/server mode but also as a Windows service! This post is about how I recreated that setup &#8230; <a title=\"Running Apache Derby as a Windows Service\" class=\"read-more\" href=\"https:\/\/www.pellissier.co.za\/hermien\/?p=1023\" aria-label=\"More on Running Apache Derby as a Windows Service\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[17,9],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1v8WL-gv","_links":{"self":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/1023"}],"collection":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1023"}],"version-history":[{"count":33,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1172,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions\/1172"}],"wp:attachment":[{"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pellissier.co.za\/hermien\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}