Standalone application inside tomcat - java

I have a simple java class that i want to run programmatically. This is basically a video player. It is also deployed along with my web application in tomcat. This should run upon a click on a particular link. From controller, here's how I run it
new Thread(() -> {
VideoPlayer.main(new String[]{});
}).start();
It is working fine. But every time I close the Video player, tomcat is also terminated. Any ideas on how to correct this?

Your GUI probably calls System.exit when you close it. That'll take-down Tomcat since they are both running in the same JVM. Find and remove the System.exit and you'll find things work-out better for you.
Also note that it doesn't make any sense for a web application to launch a video player. Think about it: once the web application is no longer running on your own personal development workstation, the video will be played on the server where there isn't anyone to watch it. The server probably won't even have a monitor attached to it. Most likely, you'll get a whole series of exceptions from the video player telling you it couldn't initialize itself because there isn't any graphics environment in which to start.

Related

Creating a background service for a finished app

I am fairly new to android development, and I want to customize an open source browser application to suite my usecase.
So what is my usecase:
I use an Oculus Quest 2 running Android. As with any Android device, you can sideload any app on it, but unfortunately the OS is very rigorous with killing background tasks, making it impossible to have Discord or Spotify running in the background while playing a game, which was my plan.
So I thought about it and came up with the idea of creating my own browser that implements the functionality to prevent it from being killed by the OS itself, and then in the browser I can open the web application of Spotify or Discord or any other web service to listen to it.
I have now decided to use the FOSS browser which I found on github and wanted to modify it to keep it open in the background. Unfortunately, I know next to nothing about Android app development and I don't even know if it's even possible to add this kind of functionality to an existing app without completely rewriting it. I hope my explanation is clear and that there is someone who can help me with this task.
Some keywords I already found out about are:
creating a service (background service)
foregrounding -> to tell the system that the app is important to the user and shall only be closed if memory is very limited
There is already one app out there which is able to run in the background of the oculus quest, so there is definitly a way of perfoming this task but unfortunatly I dont know how... yet

Java Splash Screen Application

I am running into an issue where it takes a really long time (10 seconds or so) to get through my ANT setup and running my java application. This will delay the splash screen for the jvm by at least 10 seconds to show up. Unfortunately, I can not move away from ANT to start the application due to certain constraints. What I would like to be able to do, and was wondering if anyone had a better solution, is to create a small splash screen application that would have the splash screen as an argument to the JVM so it will show up quickly and then use Runtime.getRuntime().exec("wscript....) to launch the other application. My concern is how to kill off the first application.
What I was thinking of doing is using jps within the other application to get the PID for the class that kicked off the application and then kill the Process (the first application would also have a timer to avoid it staying around if the second application did not start for some reason). I should say that there is a constraint that the main application (the second application) can only be run once and I have a bind solution to avoid this. I was wondering if there is a better way to terminate the first application. Should I use RMI or another way to tell the application to exit? If possible the less networking the better.
Wouldn't the ant Splash task do the trick?
This task creates a splash screen. The splash screen is displayed for the duration of the build and includes a handy progress bar as well.
in your first application (splash application) create a server socket with port XXX and listen for incoming messages, and apiece of code to terminate itself (e.g. System.exit();) when a message is received, and in your second application (when it is up) send a message to port XXX.
you also can implement a similar scenario using files. (1st application periodically checks a specific file exits and when it founds that file exists it terminates, 2nd application generates that specific file when it is up...

Black screen on windows logon

We're currently developing an application to control classrooms. We already know about iTalc but it won't work for us since its development is quite stuck. We feel more comfortable writing in Java rather than in c++, so we decided to create our own in Java.
For now most things are working but we got a problem with the screen capturing when on WINLOGON.
Our application uses Robot for screen capturing (we display up to 50 remote screenshots in main frame) and VNC to provide us real time remote control.
Everything works fine while the application is run as logged user, but if we wrap it in a service to start our application during winlogon credentials we get BLACK SCREENSHOTS.
After reading we learnt about the Windows Session Isolation 0 since windows vista, but since iTalc does, there's sure to be a workaround we can't seem to find in the iTalc code.
The main question is: Has anyone solved the session isolation 0 with Robot class? Also being able to tell robot to switch which session we want him to take screenshot from would be great.
We did something similar, but in c#. As long as you can make the win32 API calls from java it should work.
You'll need a separate application to actually take the screenshot and that app is started from the service while impersonating the logged in user.
Here is our C# code: https://stackoverflow.com/a/45095509/125406

Make an OSX app bundle for a Java program without user interface stay in Dock while the app is running

I tried to create my first OSX app bundle for a Java application today. It works, but there is one problem and I could not find any solution for it.
The Java application is a web server without user interface. What happens when I start the app bundle, is the following:
The app icon bounces several times in the Dock and then disappears (I guess because no GUI is being displayed?).
However, the application is still running. Web server is available and I can see the running application in Activity Monitor and stop it from there.
The main purpose of this app bundle is to provide a demo application to people who are interested in trying the server out - easily without any setup, etc.
The application should remain in the Dock and users should be able to close (stop) the server in the Dock.
I imagine that this might be configurable in Info.plist somehow, but don't have any experience with it. Or probably there is something else I can do in order to achieve the desired behavior?
Thanks for any ideas or hints.
I found the answer to this problem today:
I didn't notice it when copying configuration details into Apple's Jar Bundler, but I had this in the VMOptions parameter (Info.plist file):
<key>Java</key>
<dict>
[...]
<key>VMOptions</key>
<string>-Djava.awt.headless=true</string>
[...]
</dict>
Passing -Djava.awt.headless=true to the Java VM was the problem. After removing this parameter, the application behaved just as I wanted. It doesn't have a window but a simple menu with quit option is there, so users can easily stop the application.

Creating single instance for system tray in java

I am working in a desktop application created in java. we are working for windows version (for running on windows O.S.) of the application. When we run our application, it creates a tray icon on desktop by using systemtray as
SystemTray tray = SystemTray.getSystemTray();
I am creating single instance of the system tray, which I am creating in the main class of the application.
I am creating exe for my application. My problem is when i am running the exe file of my application, it creates tray icon every time.
I want in my application only one tray icon present on desktop and running as a service. this icon should only get removed, when application is uninstalled. It should run as service in the background.
I am not getting any way which will help me to run my application as a service and there should be only one instance running in the background.
I want to run my application by creating a tray icon as a service and should have single instance present. Please guide me in this issue.
Thanks for your all valuable suggestions in advance.
As Mudassir said, you should add a check when you start your program that tries to find another running instance of your app. This could be done by creating a specific file upon startup, and deleting it on close. If the file is already present when you start your app, it means that another instance is running.
You could also use inter-process communications, but it would be more difficult than a simple file.
For the "service" part, you could hide the main window on startup, so your app will run as if it was a windows service.
Make your application Single Instance. And please tell how you are making an .EXE file in Java?
For a tray icon to appear, your app must be running. If your tray icon appears to be there twice (or more), than your application runs multiple times. You have to add a check for this yourself.
You don't want to run your app as a windows service, as normally these have no access to the Windows Desktop.

Categories