Running a Jar File as a Windows Service Using NSSM

Running a Jar File as a Windows Service Using NSSM

Prerequisites:

  • Java Runtime Environment (JRE) or Java Development Kit (JDK): Ensure Java is installed and the JAVA_HOME environment variable is set.
  • NSSM: Download the latest version of NSSM from the official website.
  • JAR File: Have your JAR file ready. This is the Java application you want to run as a service.

Step 1: Download and Extract NSSM

  1. Go to the NSSM download page and download the appropriate version for your Windows architecture (32-bit or 64-bit).
  2. Extract the downloaded ZIP file to a directory, e.g., C:\nssm.

Step 2: Open Command Prompt as Administrator

  1. Press Win + X and select Command Prompt (Admin) or Windows PowerShell (Admin).
  2. Navigate to the directory where you extracted NSSM.

For example:

cd C:\nssm\win64        

Step 3: Install Your JAR File as a Service

  1. Use NSSM to install the JAR file as a Windows service. The basic syntax for installing a service with NSSM is:

nssm install <ServiceName>        

2. For example, to install a service named MyJavaApp, you would run:

nssm install MyJavaApp        

Step 4: Configure the Service

  1. A GUI window will open where you need to specify the details of your service.
  2. Path: Set the path to the Java executable. Typically, this would be something like:

C:\Program Files\Java\jdk-14.0.1\bin\java.exe        

3. Startup Directory: Set this to the directory where your JAR file is located.

4. Arguments: Specify the -jar option followed by the path to your JAR file. For example:

-jar C:\path\to\your\application.jar        

Step 5: Start the Service

  1. Once you have configured all the necessary settings, click on the Install service button.
  2. Start the service by running the following command in the command prompt

nssm start MyJavaApp        

Conclusion

Using NSSM to run a JAR file as a Windows service is an efficient way to ensure your Java applications start automatically and run reliably in the background. By following the steps outlined in this guide, you can set up, manage, and maintain your Java services with ease. NSSM provides a robust solution with a user-friendly interface, making it a valuable tool for system administrators and developers alike.

To view or add a comment, sign in

More articles by Gyana Ranjan Barik

Insights from the community

Others also viewed

Explore topics