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.
Related
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.
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...
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.
I'm deploying applications using Java Web Start.
To my surprise, one can pin programs to the taskbar in Windows 7, however to my understanding this is only possible if the process in which the program runs is the same than the one that is behind the taskbar icon.
With a JWS application, that's not the case so the application can not be pinned to the taskbar, as shown in the following example:
The "u" is my application shortcut, pinned (from the start menu). The other (ugly) icon is the actual application, ran in another process, creating another icon which cannot be pinned. I only get the "Close window" option.
Would it be possible to have a pinnable JWS application?
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
java 1.6 SystemTray icon does not appear on windows startup
I have java application it creates the system try icon in window OS. When I start manually it run fine. But now I put my application to window startup mean my application should run when window boot without login.
But problem is my application started and perform there tasks but it not adding the system tray icon when some one login.
And even I notice that on window boot up my application is successfully creating the TrayIcon object, creating MenuItem, adding in popup and even adding the tray icon tray.add(trayIcon); even no any exception on window bootup, but when I login
It’s not showing on system try along with time, land card icons.
I want that it should create the try icon when some one login same like when we logged in lancard tray icon appears.
Thanks
Regards
I guess that you have a timing problem. You application starts too fast and adds system tray icon before the system tray is created by OS.
Try first to call SystemTray.getTrayIcons() and print its output to log. If your icon indeed does not appear in list you are lucky. You can just try to add the icon until it appears in tray.
If it "appears" in list but you cannot see it try the following.
Add some delay before you are adding system tray. If it will help add thread that updates system try periodically. It is not so nice solution but it will work anyway even if user restarts his desktop (I am not sure it is possible in windows but it definitely possible on linux).