Background
I've made a Java application that is started by downloading a dynamically generated .jnlp file. What the application does is not really relevant, but its a screenrecorder. The user will download and start several (maybe hundreds) of these applications over time.
Problem
When the program ends I would like to delete the jnlp file that started the application. The point of the program is that nothing should be installed and nothing left behind. That includes the jnlp filed that one download to start it.
Question
Is there a way to find the jnlp file so i can delete it? (Preferably a File object)
Look up system property var jnlpx.origFilenameArg and delete it from the java application.
This worked on Java 6 update 26.
Related
This question already has answers here:
How can I write a Java application that can update itself at runtime?
(9 answers)
Closed 4 years ago.
What a really need is a java application that checks for new updates from an XML or TXT file from the internet which shows the files that have been updated like the following:
V.1.0.5
class1.java
img/img1.jpg
V.1.0.6
class1.java
class3.java
class4.java
The App. Should check Updated from his Current version to the latest and make a list of the updated files, in this case is should be:
class1.java
img/img1.jpg
class3.java
class4.java
The app Should then download this files from a link like : http://webadress.com/appfiles/XXXXXXX where XXXXXXX is the file name.
The main problem i've faced is How Can the app download and replace this files within the Same app JAR file.
i've thinked about a bootstrap (SecondP App that launch the main app and check for updates . but can't really get it to work , As it should Extract the main app jar replace and download the new update files then re-archive the files in one jar file and launch it .
Simply what i really need is an application that can update it self on file by file bases not replacing the whole jar file. as bandwidth is really a huge matter.
Thanks a lot for help in advance :)
You need two separate programs in two separate JVMs: your program and the updater. The updater (possibly on user request) checks what should be downloaded, downloads the files and then warns the user.
The user than saves his work, shuts down the application and tells the updater to patch the application binaries, for example by replacing JARs, updating databases and/or configuration files, symbolic links and whatnot.
I don't know of any framework that can ease the writing of such a system - so likely you'll have to code every piece of code by yourself. Since it's not an easy task, you should consider the conservative alternative of simply writing a wizard (there are frameworks for this) that completely replaces the binaries and works for both first installation and upgrade. Also, consider that sometimes you'll need the updater to upgrade itself!
I have written a Java application that includes a self updater. The self updater loads new program versions from a web server and replaces the application files. While this works perfectly if the application is installed e.g. in the users home directory, it fails on windows machines if it's installed in the C:\Program Files folder. This is because the JVM is executed under the user’s account which has no write access to the program directory.
If a native program, e.g. an installer, tries to write to the program folder, usually a popup appears asking the user to permit the write operation. This doesn’t happen for java applications. Why?
Is there any way to achieve that a write operation of a Java program to a restricted folder brings up the security popup so that the user can permit access to that folder?
Thanks for your responses. According to the answers I see the following options:
Java Web Start
For me this is not an option for end users. I think that no one can expect from an ordinary end user to know what Java Web Start is, what it’s good for and how it’s used e.g. I doubt that an ordinary Windows user knows how to uninstall a Java Web Start application.
Use an exe-launcher with manifest to launch the Java application
As far as I understand this solution the exe-launcher would request extended execution right at application start. This is not exactly what I want, cause for my use case it would be sufficient to get extended rights if an update is available and not on every application start.
Perform the update operation by calling a native executable
One could call a native executable to let it perform the update operation. In this way the application would only request extended rights if an update is available. This sounds not bad but includes some native coding for Windows and doesn’t work on other platforms.
Install a launcher in program folder and the application in user home
One can place a launcher in the program folder that calls the application that is installed in the user’s home directory. In this way it would be possible to update the application in the user’s home folder.
I use InnoSetup for installing my application on Windows and as far as I can see it a split installation is hard to achieve with this installer and probably with other too.
Install the complete application in the user’s home directory
Because the user has write access to his home directory there is no problem at all. For me this looks like the best option cause of its simplicity.
If you are using inno setup compiler to generate your launcher, then you can change your app directory permission.
For example, if you need full control and want to update files under AppName/data folder
[Dirs]
Name: "{app}";
Name: "{app}\data"; Permissions: everyone-full
[Files]
Source: data\*; DestDir: {app}\data\; Flags: ignoreversion recursesubdirs createallsubdirs; Permissions: everyone-full
Unfortunately the increased permissions need to be requested when you first start the program, you cannot promote to them later. Programs that look like they do that are actually restarting themselves with the higher privs behind the scenes.
I had a problem like this a few years ago with a Java app and in the end I installed the application to the user data folder instead of program files as otherwise the auto-updating was a nightmare. You can still add it to the start menu so to a user it looks exactly like any other program.
I need way to detect which jnlp file which started current app. in my case I'm developing an application that is started by jnlp file that contains some additional info. I need to delete this jnlp file while app is closing. app cannot be started in any other way. is it possible to get this information, and if it is, how can i do it. thx for answers
I need to delete this jnlp file while app is closing.
That choice is not available to the developer. It is a choice of the user, their JRE and system settings.
What application feature are you trying to implement from this?
Originally I had an applet that contained SQL server/jdbc stuff and wanted to use that applet in html but I guess it's not good to use SQL in html? because i kept getting millions of errors/exceptions and realized my applet would only work if i commented out my SQL code.
but anyways, is there a way that I can have a button on an html page that when it is clicked it will run the runnable JAR application not the applet? without causing errors..
I'm not sure what a JAva Web Start is or what a JNLP is but if anyone could explain/help? the Oracle Website doesnt explain well enough like how do i create a JNLP?
I currently have a runnable JAR file that was exported from eclipse that opens & runs when I click the icon
You are correct that Java Web Start is what you want to use. You have your JAR file built already, so you should be good to go by following this Deploying a Java Web Start Application tutorial
This will walk you through signing the JAR file, creating JNLP file. This web site contains an example of a JNLP file, and also contains more documentation on the structure of the JNLP file here
You'll then create a few simple lines of JavaScript, to be triggered when the user clicks a button. Something like this, as mentioned in the tutorial:
deployJava.createWebStartLaunchButton(URL_TO_JNLP, '1.7.0');
I have a Java application ready to be deployed. I tried using Java Web Start (JWS) to launch my application. My application was able to launch it loads the MainFrame but some of the functionality does not work. For example my search button (which creates a new thread to search information over the internet) is not working and several other buttons. My application works perfectly as intended when I run it using the typical java -jar or by double-clicking the JAR file. Do you have any ideas why did it happen? Or am I using a wrong technology for deployment? When I read about JWS the thing that I really like is the auto-updating of the application when new versions are released for the app. I really want this feature for future updates.
Solved:
I wasn't aware of the of Web Start Console. My problem is solved now as I was able to see the stack trace. It has something to do with permissions and my JAR file being unsigned.