{"id":1452,"date":"2021-05-05T07:47:42","date_gmt":"2021-05-04T19:47:42","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1452"},"modified":"2021-05-05T07:47:42","modified_gmt":"2021-05-04T19:47:42","slug":"java-as-a-windows-service-with-nssm","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1452","title":{"rendered":"Java as a Windows service with NSSM"},"content":{"rendered":"<h2>Pre-requisite<\/h2>\n<ul>\n<li><a href=\"https:\/\/nssm.cc\">NSSM<\/a><\/li>\n<\/ul>\n<h2>Installing a Java Service<\/h2>\n<ol>\n<li>\n<p>Register a <strong>java application<\/strong> as a <strong>windows service<\/strong> using the following syntax:<\/p>\n<pre><code>nssm install &lt;SERVICE_NAME&gt; &lt;JAVA_EXECUTABLE&gt; &lt;JAVA_ARGUMENTS&gt;<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>nssm install \"JavaService\" \"${JAVA_HOME}\\bin\\java.exe\" \"-jar java-service.jar --spring.profiles.active=dev\"<\/code><\/pre>\n<\/li>\n<li>\n<p>Update the service with <strong>application directory<\/strong> using the following syntax:<\/p>\n<pre><code>nssm set &lt;SERVICE_NAME&gt; AppDirectory &lt;JAR_FILE_DIRECTORY&gt;<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>nssm set \"JavaService\" AppDirectory \"C:\\apps\"<\/code><\/pre>\n<\/li>\n<li>\n<p>Update the service with <strong>description<\/strong> using the following  syntax:<\/p>\n<pre><code>nssm set &lt;SERVICE_NAME&gt; Description &lt;APP_DESCRIPTION&gt;<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>nssm set \"JavaService\" Description \"A custom java service.\"<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>Displaying the NSSM details of the Java Service<\/h2>\n<p>Use the following syntax to display the details of the services:<\/p>\n<pre><code>nssm dump &lt;SERVICE_NAME&gt;<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>nssm dump &quot;JavaService&quot;<\/code><\/pre>\n<h2>Uninstalling a Java Service<\/h2>\n<p>Use the following syntax to remove a java service using nssm:<\/p>\n<pre><code>nssm remove &lt;SERVICE_NAME&gt; confirm<\/code><\/pre>\n<blockquote>\n<p>confirm parameter here specifies that we don't want to see the gui confirmation.<\/p>\n<\/blockquote>\n<h3>Example<\/h3>\n<pre><code>nssm remove &quot;JavaService&quot; confirm<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pre-requisite NSSM Installing a Java Service Register a java application as a windows service using the following syntax: nssm install &lt;SERVICE_NAME&gt; &lt;JAVA_EXECUTABLE&gt; &lt;JAVA_ARGUMENTS&gt; Example nssm install &#8220;JavaService&#8221; &#8220;${JAVA_HOME}\\bin\\java.exe&#8221; &#8220;-jar java-service.jar &#8211;spring.profiles.active=dev&#8221; Update the service with application directory using the following syntax: nssm set &lt;SERVICE_NAME&gt; AppDirectory &lt;JAR_FILE_DIRECTORY&gt; Example nssm set &#8220;JavaService&#8221; AppDirectory &#8220;C:\\apps&#8221; Update the service [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1452"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1452"}],"version-history":[{"count":1,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1452\/revisions"}],"predecessor-version":[{"id":1453,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1452\/revisions\/1453"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}