Java service with GUI tool - java

I have an application with GUI. GUI is used for settings management only. Now I need to turn this into Windows service. I thought of splitting my app into 2: service itself and GUI-tool for providing settings. Main problem is that I'm not sure, how this tools should "communicate". Settings are stored mostly in files, and after new settings applied, service should restart.
As for now, I thought of admin-tool sending few requests to service over TCP/IP, that also allows to control service from the network. Problem is that I need to hardcode, or use some text file, to set default port on which service would listen for admin-tool connections after it's installation.
May be there is any alternative solution, which is more suitable here?

You are creating a service. If all you need in the communication layer is being able to stop and start the services, then you don't need to open a port and start listening. The system gives you means to do that with commands that you can run. you are talking about windows, so for example you can run the command "sc start MyServiceName" to start service "MyServiceName". there is also a command called "net" which allows you to start and stop services. These OS commands can be then called from java code in various ways that are available to execute external code.
here is a link that shows how to do that with sc command, check the accepted answer: start-windows-service-from-java
here is another link that shows difference between two commands "sc" and "net": net-start-service-and-sc-start-what-is-the-difference
Note that "sc" supports starting services on remote machines: simplest-way-to-restart-service-on-a-remote-computer

Related

Java SSH client with GUI, Mindterm alternative

In our project (CMS) we are currently using Mindterm for launching SSH terminal to Network Elements and different Virtual Machines. Client download .jnlp file that launch Swing based GUI with ssh terminal to configured address.
Since mindterm is getting out of support at the end of this year (2021), we are looking for replacement, my question is can anyone recommend something providing similar functionality, we don't want into writing this by our own.
Thanks
P.S. I know that e.g. Putty, mRemoteNG exist but customer want to have ability start preconfigured with IP address terminal from CMS application.

View running application output in the browser, how?

I have a simple cloud IDE,I want to make it able to build and run applications remotely, the target application's source files will be in a remote server in isolated virtual machine (e.g Windows 8.1,or Ubuntu 14.04). It's not difficult to build that application but how to run it and view its output to users ?
What if it's a desktop application (suppose it's written in C# or Java or Python)?
Note: users access there applications only using browsers (e.g Firefox,Chrome,...)
Edit: desktop application may contains GUI stuff not only console ;)
You need a web application.Now this web application when loads send request to backend code that backend code will do SSH to remote machine and read the file from specific location.Now that read stream will be send back in response and displayed on web based UI. In these type of application few thinks matters.
1) Like if you whole file at once then it will take time to display that content to user.Better idea will be read around 100 lines at once and when user scroll down then again send request to web server to read next 100 lines in this way you can decrease response time and better user experience.
Each of the languages you mentioned offers a Web Services framework of some kind. Pick one, and implement something that a) starts your app, b) shows the output. Depending on the processing time (how long it takes to complete) you might even get away with just one.
You can go for a self-contained, standalone service:
C#: Is it possible to create a standalone, C# web service deployed as an EXE or Windows service?
Python:
Best way to create a simple python web service
Java:
https://technology.amis.nl/2009/06/05/publish-a-webservice-from-a-poja-plain-old-java-application-that-is-out-of-the-container-using-endpoint-class/
Alternatively, you might use a container (server) for your app, like Apache with mod_mono or IIS for C#, Tomcat, Jetty, Jboss for Java, Apache with mod_wsgi for Python (just examples).
The web service would probably sit on the remote machine, so it could use system calls ('command line') to run your core app, and then it would send the results over http. Since you mention GUI, there could be more layers to the solution:
The GUI - static HTML, desktop app, sending requests to the 2nd layer, say displaying dropdowns for parameter1 and -2
The Web Service - takes the params from the request, say http://remote.machine.land/start/app?parameter1=X&parameter2=Y, runs a local command like /home/users/myapp.sh -parameter1=X -parameter2=Y
The application itself - not necessarily aware of any internet out there.
This way you stay free to change/enhance any part at a time, call the 2. layer programmatically, introduce load-balancing, etc.
3.

How to run external application from a Java EE web application?

I have been working on a Web Application for Intranet use only. I work with Apache 7 and Windows Server 2003.
In one of my page, I need to open an external application that we can locate in C:/Program Files/etc... with some parameters already initialized. Of course, the user has to use the web application on the server to make it work (that will be the case).
To open the application, I use the ProcessBuilder object.
The problem:
When I work locally with Eclipse and run the server by hand, it works perfectly. Any application can open itself from a web page.
But when I use the tomcat windows service (and that's what we want to use on the server), it just never launches. Or to be more specific, it launches and stops the application directly. No java errors thrown and process.waitFor() with an exit value of 0. The fact is that we can run processes via the web application (I tried to run simple batch files), but when there is an UI involved, it will never appear.
Again, on the server this time, if I launch tomcat7.exe (that we can find in the %CATALINA_HOME%/bin directory) with a double click or cmd, the UI in the web application will appear. If I launch it with services.msc or tomcat7w.exe or tomcat7 start via cmd, it will not.
I thought of several things:
use another user to start the service
change the way the service is launched (StartMode: jvm, java. I did not succeed with exe)
I read Tomcat 7 Windows Service How-To many times but didn't find out anything to solve my issue.
Have you any idea of what is happening, and how to solve this issue ?
What is the big difference between running tomcat as a service and from the command line?
Option 1
If you open your service's properties window, go to the Log On tab then check the "Allow service to interact with desktop" check box you will get the behavior you want. Also depending on what app you what to run you may need to change the log on account.
see Launching GUI App from Windows Service - Window Does Not Appear
Option 2
Did you try start a cmd and there use
start /c "c:\path to\exe"
in cmd.exe type
help start
Option 3
You will need a daemon service that is not run as a service. windows puts certain restrictions on service apps.
This sleeping app can be started by tomcat or other your self. it can listen on a port or poll a folder for a new file, and when it gets a job to do it starts the app you want. Via port or text file you can send the parameters.

Hardware support from a web application

I have a web application running with support for some specific pieces of hardware. This is achieved in the following steps:
User runs a small installer that places java files (and a couple
others) on the client machine. The main piece is a jar called "hardwareManager"
User visits web app. The web app runs a java applet which, due to
a .java.policy file placed during the install, has permission to
interact with the client machine outside the browser sandbox.
The applet checks to make sure the hardwareManager is running,
and if not runs a command to start it.
User interacts with the web app which sends commands to the applet via
javascript. The applet then writes commands to a text file
on the client machine. The text file is constantly monitored by the
hardwareManager which runs any commands it reads in.
This works, but seems clunky. I have a couple ideas on how to improve it, but I don't know which, if any, are even worth trying.
Would it be better to set up the hardwareManager as a socketServer and have the applet connect directly to it, rather than going through text files? Is that even possible?
Is there a way to eliminate the applet altogether and have the javascript talk directly to the hardwareManager? Maybe by writing the hardwareManager to be a local http server? What port should it run on? Do javascript xss limitations fit in here somewhere?
It would be less clunky to start the Java application using Java Web Start. This would remove the need to daemonize or install the Java hardware manager.
Another alternative is to use a built-in browser inside Java. I supose this is not an option, since you depend heavily on Javascript (I suppose to provide a rich client experience).
If you already have to install something on the client machine, why did you make the choice to go with a web application?
Talking from experience: We had a Java EE application which needed to print to PoS printers at the client site. We installed a small "synchronizer" application that connects through SSH and synchronizes all clients files. Afterwards, it loads the JAR and executes the program. This program connects through RMI with the server and subscribes to a JMS queue to receive the print assignments.
Applied to your case: Why not let your Java application connect to the server directly? You can use HTTP, SOAP or even JMS over RMI. You can then launch the hardware command from the server (instead of from the limited JavaScript webbrowser environment). This way, you get tons of features: authentication, buffering of commands, and you can even share hardware between multiple clients.
Schematic:
<----AJAX------> Web browser
ApplicationServer
<---HTTP/SOAP--> Java hardware manager application
You can launch the Java application using Java Web Start, which allows you to update the application automatically (instead of needing to pass every client a new installer).

Difference in viewing a swing application via a remote client and viewing directly

So I have an executable jar file which when run in windows or in Linux by using the command
`java -jar filename.jar`
the output is this.
But when the same thing is viewed via a remote connection using VNC client, the output is reduced to this
I have tried changing the resolution of the vncserver instance by using -geometry attribute and have also tried supplying values for "-cc" and the "-depth" attributes. But to no avail. Can someone tell me what I have to do so as to get the intended display properly in the vnc session as well?
This may be seen when the GUI is not constructed on the event dispatch thread. The remote connection adds enough latency to expose the underlying problem.
Because the two images have differing dialog names, verify that both represent the same code. Also, check the remote server's .vnc log to see what window manager is being used.
Addendum: I'm not sure what VNC server your server is using, but you may be able to edit $HOME/.vnc/xstartup to specify the window manager. Gnome's Metacity has worked for me.
VNC Clients also have settings, like color depth etc, that effect the output quality. And it also depends on capabilities of VNC. Which SErver and and which client are you using? If you have set in in the VNCSErver, check the params of VNCViewer.

Categories