NSSM service does not show GUI - java

I have a maven/java project i am trying to make a windows service. I have a .exe which is used to distribute the program, and now I need to make it a windows service.
The executable works fine by itself and shows the GUI.
I have ran everything in elevated cmd & powershell terminals.
When i install the service: NSSM_TEST: INSTALL: The operation completed successfully.
When i start the service: NSSM_TEST: START: The operation completed successfully.
When i run status: nssm.exe status NSSM_TEST SERVICE_RUNNING
The program also shows up under the running processes, but shows no gui or system tray symbol (which is implemented through java).
Parameters in mssn GUI:
Application path: C:\Users\skakk\sweat-tek\DynaGrow\DynaGrow-app\target\dynagrow\bin\dynagrow.exe
Startup Directory: C:\Users\skakk\sweat-tek\DynaGrow\DynaGrow-app\target\dynagrow\bin
No arguments.
Log on config:
Any help would be very much appreciated.

Related

My script runs perfectly through bash, but using a service to call it gives me errors

I am currently trying to develop a program that displays repeating images (using Java and Jframe) using a raspberry pi 4.
However, I have a small shell script that compiles (and runs) said program which works perfectly when I call it manually. However, I am trying to have this happen on boot through creating a custom service that calls upon that script. The problem arises when the compiled program is being run as I get the error
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
Now I did a bit of research and have tried to use the command (in the shell script) export DISPLAY=:0.0 however, this also gives an error of
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
I am not quite sure on why the service is trying to connect to a X11 window server either.
This is the service:
[Unit]
Description=myservice custom script
[Service]
RequiresMountsFor=/media/pi/PICS
ExecStart=+/bin/bash /home/pi/Desktop/PicScript.sh
Restart=always
[Install]
WantedBy=multi-user.target
And finally, the little shell script:
javac /media/pi/PICS/App/App.java
export DISPLAY=:0.0
java -classpath /media/pi/PICS/App App

Error after deploying a javafx application

I have developed an application in javafx. It works very well on my laptop even when I deploy it and run on my computer, but when I install it on another pc the application starts normally, but does not display any interface (the task bar it is present). When I run the .jar with java -jar monapp.jar command I have an error in console
error shown in the console
Please help.

Steps to deploy play framework application to production environment?

I got stuck in the steps to deploy the play-java application to standalone server. I am using Ubuntu instance running onEc2 machine. After reading the official documentation I followed these steps:
Install typesafe activator to $Home/activator
Copy my project folder to $Home/activator/projects using Jenkins
Run cd $Home/activator/projects/project
Run dist command. It generate the project sh file
Run cd $HOME/activator/projects/sample/target/universal. It shows me three things i.e. sample-1.0.zip , tmp.
Run unzip sample-1.0.zip
Run cd $Home/activator/sample/target/universal/sample-1.0/bin. It shows me two scripts i.e. sample (for mac and linux) and smaple.bat (for windows).
Now, I tried to run this command as documentation says: sample-1.0/bin/sample -Dplay.crypto.secret="abcdefghijk" but it got stuck and shows nothing except a prompt on terminal.
What next steps are required to run the application in daemon mode. So that server will continue to run always?
Another question is why do I need to follow these steps because just after copying the project I can easily run activator run command to sample folder to run the server.
EDIT-1
Now I am getting Error: Could not find or load main class play.core.server.ProdServerStart while running sample -Dplay.crypto.secret="abcdefghijk" command
Play Framework modes
Play like other frameworks can run in different modes because we are usually like to run our program in different situation and these situations need their configuration. Production is one of play modes. In this mode as the name suggested we are ready to deploy our application where user can use.As a result requirements are different.
Some common configuration in Production mode :
We are confining https
Using production data base not testing one
Play doesn't show errors
Play framework run as long term process and if you are log out of your server your application will run
If your app fails Play will clone another application and run that so your app run forever except you turn it off.
and so on (it is based on your Production config file)
Your answer :
If you just want to test your app in remote server and see what happened, it's okay to use activator run this command runes Play app in development mode and application will killed if you exit or log off (error will shows up and so on). But if you want to use your app for Production it is necessary to run all of these steps.

notepad.exe is not opening in tomcat but works in eclipse

My requirement is to open the notepad using processbuilder.
If we run the
C:\>notepad.exe
In command line or eclipse (through java using processbuilder )the process is created like below.
Name PID status UserName
notepad.exe 8380 Running Selva
The process is created in task manager and also notepad is opening and we can able to execute the command again and again.
But If we run the command from Tomcat using java process builder(Tomcat started through services.msc) the process is created like below.
Name PID status UserName
notepad.exe 8380 Running SYSTEM
The process is created in task manager.But notepad is not opening in the system and also we can't able to run the command again.Because it's showing,
"The process cannot be accessible,because it's being used by another process"
Why the process is created with the name "SYSTEM" instead of "Selva" in tomcat and why the notepad is not opening.
How to fix this issue?
Any help will be greatly appreciated!!
Services run in the background - regardless whether a user is logged on or not. Thus they usually have no access to the GUI. Windows redirects their GUI output to a 'hidden' desktop.
This problem is per Windows design and not related to Java. See also Swing JDialog is showing fine when I run it from eclipse but not working from windows service(services.msc)

How do I run a Java .jar file as a Windows service on Windows Server 2008?

How do I run a Java .jar file as a Windows service on a Windows 2008 server? I have a jar file called SomeJavaFile.jar located under the C:\SomeDirectory directory on a Windows Server 2008 box. I usually just run this jar manually in the command line with: java –cp SomeJavaFile.jar com.ctg.SomeJavaFile and I let it run 24/7.
The problem with our Windows Server is if it restarts I need to run it as a service so it will automatically start as a service upon startup, because our processing for Vistakon runs 24/7. I have Googled around and tried to use a service wrapper and the sc.exe command to create the service.
I put the wrapper service.exe in the C:\SomeDirectory\. I use the following command to create it: sc.exe SomeJavaService binPath= “C:\SomeDirectory\service.exe \”java –jar C:\SomeDirectory\SomeJavaFile.jar\”” type= own start= auto error= ignore. This creates the SomeJavaService service correctly but when I try to start it I get an error that says the service on Local Computer started then stopped.
Some services stop automatically if they are not in use by other services or programs. Do I need to alter my sc.exe command to have the exact previous working command line maybe, by adding in the com.ctg.SomeJavaFile? So should I change This jar should just run in the background and constantly poll/ping the C:/poll directory then if there is data present it processes the data and sends an export file to another directory.
I have used this same .jar file for years successfully and it hasn't changed, but I cannot get it to run as a Windows service. This is the site I use to get the service wrapper http://code.google.com/p/simple-service-wrapper/. Any help would be greatly appreciated!
"winsw" is the standalone version of the Windows Service installer shipping with the Glassfish Java EE reference implementation.
Works well, but is not a fully polished product - I have used it for exactly this purpose for a couple of years. Requires .NET in some recent version on the Windows machine.
https://github.com/kohsuke/winsw
I think that the best bet would be wrap your java app with Procrun of Apache Commons Daemon .
Procrun is a set of applications that allow Windows users to wrap
(mostly) Java applications (e.g. Tomcat) as a Windows service.
The service can be set to automatically start when the machine boots
and will continue to run with no user logged onto the machine.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat (that triggers the jar file)/.exe as a System service with all the required call back methods to SCM.
Note : 1. Wrapping the process with sc.exe / srvany.exe would not work as it does not have any call back process to the SCM (Service Control Manager). 2. And java service Wrapper is a third party API (many are LGPL licensed).
If you start your Java code from commandline by using java -j some.jar does it run until you terminate the program, or does it stop by itself?
There needs to be a NON-Deamon Thread, that is running all the time. A JVM will terminate, if there is no thread running, that is not flagged as daemon.
If you have a little budget, buy an installer tool. I use instll4j. With that tool, you can create service launcher and install them during instllation.
The following solution is working fine for me having OpenFire Connection Manager (which is a jar file) running as service on Windows Server.
Download and install the Non-Sucking Service Manager
I didn't use the batch made by OpenFire team, because it didn't work for me (dependencies not found error...) So, make a batch file with the following code :
#ECHO OFF
cd /D "E:\connection_manager\lib"
java -jar startup.jar
and save it as cm_startup.bat in the bin folder of connection manager.
After that you can create the service with NSSM.
So, open a cmd.exe and run the following command :
nssm install ConnManager "E:\connection_manager\lib\cm_startup.bat"
.
Doc & examples
More documentation and examples for the Non-Sucking Service Manager here : https://nssm.cc/usage Actually NSSM as a lot of options available.
Here is a more complexe example :
nssm install solr "%JavaExe%" -Dsolr.solr.home="\"%CD%\solr"\"
-Djetty.home="\"%CD%"\" -Djetty.logs="\"%CD%\logs"\" -cp
"\"%CD%\lib\*.jar"\";"\"%CD%\start.jar"\" -jar "\"%CD%\start.jar"\"

Categories