Exercise 3: Run a Java Server as a Windows Service
To create a Windows Service, use the J2WinService component of the J2Exe download and simply repeat the same instructions you followed with J2Exe in the first part of the "Exercise 1: Develop a Simple Java Application with Its Own .exe" section. However, after reviewing your "Input" options and before choosing your "Output" options, select "Service" (See Figure 8
) and enter the following additional information:
- Service name: MyServer
- Service description: MyServer Description
- Interact with the desktop: checked
- Service type: Service that runs in its own process
Start type: Service started on demand or Service started automatically during system startup.
To install this service, write "MyServer /install" in the command prompt. To uninstall it, write "MyServer /uninstall".
Find Your Application's Balance
Java's power is its platform independence, but it comes at a cost—the specific features of each platform. The best approach is to build platform-independent applications that preserve the platform-specific features of their target environments. I hope this article helps you to find that golden balance.