JAVA: Opening an application when the user starts their computer - java

I have an application which has a purpose to run when the user first runs their computer.
However, I'd like to make a check box on the app that enables/disables the application loading when the system is started. Is there any way to do this?
Thanks

I recommend you to create a service under windows. My suggestion is http://winrun4j.sourceforge.net/

This question has been discussed in SO time ago:
Code for Auto starting a java application on windows startup
Auto startup for java desktop application?
However, maybe the easier solution is to create a batch file,like suggested in the first link, to run your application as the user logs in.
If you want to enable/disable the startup through a checkbox, the first and simplest solution that comes to my mind is this: you can make a method, invoked by the checkbox listener, that edits the batch file and enables/disables the line used to run the application, in the batch file.
If you have Windows 7, read this tutorial.

Related

How to get system login time through java program

I am building one application using Spring 4.0 where, I need to know System login and turn off time in my application.
I didn't try anything for this because I really don't know how to do this even it is possible or not.
While we open system is there any file in OS where time is storing automatically, if no is there any other way to solve this.
Please help me to do this.
Thanks in advance.
in windows :
#net statistics server
The line that start with "Statistics since …" provides the time that the server was up from
in linux use
#uptime
run that command using process builder in java.

One-time Java Configuration file on a desktop app

I am doing now a desktop app like a organizer. When the program starts, it has 0 tasks, obviously. I go adding more tasks, but when I close the program and then restart it, all the tasks I have done will be on null.
I think I can use a file that the program will consult. This file will have all the relevant information for load all the tasks.
But, and problem comes here, I want to make a question like "Where do you want to save the configuration file?" It is like Eclipse`s message at start with the workspace. The idea is that the message will only be show until the user specify a valid route.
Can we do this in Java?
Use java.util.prefs.Preferences: https://docs.oracle.com/javase/8/docs/api/java/util/prefs/package-summary.html

Launch Java application from another application

What I want to do is to have my main Java application to update another java application using Java Web Start and then run the second application "silently" upon user request.
I know Runtime.exec to call javaws and silently import the second application in the cache. I can do that when the first application runs and then I am sure I have an updated copy of the second application. My problem is how to run the second application without showing the Java Web start "Verifying application" window.
Doing some research I see no way to avoid that if I execute the .jnlp. I am wondering whether I can run the second application calling directly the downloaded jar files by passing Java Web Start.
Any Ideas?
Thanks
You have basically two possibilities here:
you can use the JNLP Api service and use the DownloadService;
or use the URLClassLoader and load the remote class.
I don't know if this what you want to do, may be for you it seems as a trick around, forgive me if so...
Why don't you run it as exe, by using process object?
Process process = new ProcessBuilder("C:\\...Desktop\\MyExe.exe").start();
And you can convert your app to exe easily by using jsmooth

JNLP SingleInstanceService Use in Command Line JAR Application

I have a desktop Java application that is run from the command line, which takes in some arguments and performs some actions based on these arguments.
Currently, the application is instantiated periodically, performs its function and then exits.
The issue is that the users are unhappy with the amount of time it takes for the application to initialize. In order to work around this, I thought of simply toggling the visibility of the application when it is finished and setting up some kind of IDLE state.
I was trying to figure out a way to pass in new arguments next time the application needs to do work. I found out about SingleInstanceService and was wondering if it is possible to make this work with my application? It's unclear to me what I need to do so that the Single Instance Service runs on the client PC.
Alternatively, is there another solution for my communication problem? I would rather not depend on File I/O to trigger the application's logic.
Thanks.
AFAIK The JNLP API is available only if you launch your application using java web start (JWS) technology: read more here: http://java.com/en/download/faq/java_webstart.xml
If that is an option for you, oracle has some example of how to use the SingleInstanceService here
Implement and Register SingleInstanceListener. It will be invoked with the main-args when new instances of your application is launched.

Refreshing Swing application with Eclipse/MyEclipse

Say that we are writing a Java Swing application and we use Eclipse or MyEclipse to develop it. In web applications, you make code changes, you save and your ant deployment file takes care of the deployment of the changed files. Then you just refresh or hard refresh the web page and the changes appear there. Can we do the same thing for a Swing applications so that we don't have to close and open the program from the beginning every time we make a change?
I don't think so because you need hot code replacement ! Maybee using another framework.
You can't simply do that because once JVM is started, it loads the class files once and will not reload it untill next loading request. But you can use ClassLoader to load modified class files dynamically.
The following two articles may help:
IBM article on "hot class swap"
"Who Said Runtime Class Reloading Is Hard in Java?"
The first one is in Chinese, but you can look at the code and the result. I think the second article is more helpful for a GUI application.
In MyEclipse you can start your application in debug mode instead of run mode and changes you make will be pushed to the target VM; if changes you make cannot be replaced you'll see a dialog informing you the replace failed and you will need to restart your application. You don't need to place any breakpoints in the application, just starting in debug mode is sufficient.
As Guillaume states above, changes to the class structure will typically not be hot-synched, but changes within existing methods should be fine.
Obviously, how successfully hot-synched changes affect your running application would depend on your application design.

Categories