I already have a working code to download certain file from my server. This file is in an executable (a patch installer). I would like to know if it is possible to launch the executable after my java application has downloaded in its own directory. If it is, may I pleas know how?
Also, I know I am asking for too much here, but is it possible to then delete this installer from the computer after it has installed the patch?---I've been working on this but have stumbled upon a lot of nothing...
Thanks a lot in advance!
Look at the java docs for the class RunTime, this should allow you to run an executable providing you have permissions to do so.
Runtime.getRuntime().exec("command") will execute the input as if you entered it in the command line. So, if you know the path of the exe file (which you should, since you downloaded it), you can launch it like this:
Runtime.getRuntime().exec(executablepath);
Normally you can delete a file by using File.delete(), but in this case the command will still be running if you add delete() right after exec() and it won't be able to delete. Hope that helps!
Related
I am trying to run a executable jar file I made in Intellij on JDK 11.0.2 that contains a GUI system. I have java 8 and Java SDK 11.0.2 installed. Whenever I double click the jar file I expect the main gui login screen to come up, but nothing happens. I have tried other options such as trying to run it through cmd (it gave me an access error) and the HKEY_CLASSES_ROOT\jarfile has the command: "C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe" -jar "%1" %* already.
Cant comment quite yet on other peoples posts so ill just submit an answer, tho its gonna be more of a swing and miss probably.
Id recommend opening that jar file with a java decompiler (The one i had in mind is jd-gui) and checking the integrity of the code, file system, and, in general, just check arround for common errors when packaging, maybe you included something you shouldnt in the class and hence why the problem, or its crashing on load cause of a missing reference you had linked to with a relative path which got broken upon moving the file, those are the two big ones that come to mind that you should check first upon opening the file, other than that, i cant provide much more insight, godspeed to you!
I am looking to write a jar filer to a folder in the computer, that is located at the Jar file itself.
Image
Basically what I want, is to make the program start everytime that windows will run, using the "Startup" folder.
I want that when I start "Guic" Jar file, it will write the Jar file "Surprize" to the windows folder "Startup".
I am sorry if this is not understandable.
I think what you want to do is to run a java application every time your computer runs. I haven't done it before and don't have much time right now to search it in-depth, but i think this will help you. If I am wrong about and I haven't get that right, please let me know. Also, if the answer I provided you is not enough inform me so I can try it on my own and get back to you.
Hello all :) I love stackoverflow where I always find answers but this time I could not so personally asking... Its bit lengthy please go through it.
I am creating a java application where one of my resource is an exe file which I need to call in the java code. But later I would convert the whole java code to a JAR file... and I would add the JAR file and the exe file for the Setup file for installation process. So when I extract the files I want my JAR file to call the exe file while running... I am doing this all in Eclipse :)
So my doubt comes here which path I should put up in the java code... ? So that it will always call the file the exe file from the same directory where the JAR file is also present.. :)
Any help would be great :) Thank you in advance :)
Assuming that you control the whole installation process; and that you also control the script that later starts a JRE to run your JAR within; my suggestion would be: simply use a property here.
In other words; your installer knows that it copied JAR and EXE to D:\example\ for example. Then just make sure that your JAR is started like:
java -jar D:\example\your.jar -D your_path=D:\example
(this is just meant as example, you would have to work that out, probably the \ in there need some special treatment for example)
Then your application can simply query for that system property "your_path" and take the value from there.
Alternatively, you could try this solution that works "pure java".
completely new to this so apologise for the question.
I have current been asked to deploy a jar on a linux server at work. I have sucessfully logged into ther server using ssh and transferred my jar on to it. However when I run any java command it says command not found.
I ran
locate java
and
locate jar
which both return, so im guessing java is installed? What do i need to do?
Thanks in advance
It sounds like your path has not been set up to fit your Java needs. You can do either of two things:
Type out the full path of where java is located, and use this full path instead of "java".
Edit your PATH to include java. Here's some information on how this is done: http://www.java.com/en/download/help/path.xml
I think you have to check to make sure that java is installed and the path for it is set too.
Whe you type locate jar it's most likely going to return any other jar including the one you have just added. To know if java is installed, you should instead use the following command java, if the result is something like the program cannot be found... then it means there is not java. You could also use java -version which will also tell you which version is installed. If it's for running purposes then you will be good with that.
First try the command which java, it would show you if you have java installed if not download it and install,run it. Then you can run the jar file as per you requirement. This link shows you how to install and configure java.
http://www.java.com/en/download/help/linux_install.xml
Thanks & Regards,
Alok Thaker
so, I've been doing some searching, and i can find somethings on how to run an external application, but i cant get them to work! I've been working on this for a while, and its really annoying.
what i want to do is run a .jar file in the directory
C:\Program Files\AVTECH\NPS\Files\bin\NPS.jar
and I've tried a bunch of different things with the code
Process p = Runtime.getRuntime().exec("dir goes here");.
also
Process p = Runtime.getRuntime().exec("C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar");.
if i'm correct, it uses command prompt to do this? or at least the MS-DOS language. i did some of that kind of thing a few years ago, but i don't remember how one would do this... I've never worked with this kind of thing in java before...
could someone help please? thanks in advance.
Runtime.exec() is working just like if you were typing a command.
Launching a jar file is not working : you have to invoke
java -jar /path/to/my/jar
Check Oracle's documentation on how to execute a jar file.
The actual command should be java -jar C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar. I mean -- if the jar file is indeed executable, this doesn't mean it will run, by just trying to invoke it. You need to tell Java to run it as shown above.
In addition, MS-DOS is not a language -- it stands for Microsoft Disk Operating System. Nowadays, you have this as a Command-line Prompt (Shell) built into Windows.
You need to run the command as a call to the executable and a set of arguments. Check this version of Runtime.exec(String[] cmdarray). If need be, there's also a version of Runtime.exec() that takes a base directory in which to start the executable.