tiny exe to launch a java application
Some questions are like: How can I package my java app into an exe ? This is not what I am going to ask.
I can launch my application by doing the following:
java -jar myApp.jar
That works perfectly (Assuming the machine has java 1.5.0 or >)
Now what I was thinking of having is a myApp.exe file.
What it would do is the following:
- check if java is installed on the machine and its version. if java is not there it would prompt a dialog to say: "you need to install java to run myApp" exactly like e开发者_高级运维clipse.exe does if it does not find java. it would then terminate.
- if java is there, then effectively run the command javaw -jar app.jar and spawn the process.
any idea ?
JSmooth does exactly that.
I've done a similar thing using NSIS and Launch4j. NSIS allows you to create a setup script as you want with some wizard windows etc., Launch4j allows you to wrap the executable jar into an exe file. I've used both to distribute a swing application to 4000 users. For more precision, I had to check that java 1.5 or later was installed before starting the setup.
Something like that batch script wouldn't work?
@echo off
for /f %%j in ("java.exe") do (
set JAVA_HOME=%%~dp$PATH:j
)
if %JAVA_HOME%.==. (
@echo java.exe not found
) else (
java -jar myApp.jar
)
From this question: Discover from a batch file where is Java installed?
I left this question unanswered for a very long time. I think it's fair to say that there is no such easy way to do so. JSmooth looks like a good tool, but it's pretty limited. Eclipse has written its own solution and so many other solutions written in java deployed as exe.
Assuming your app. has a GUI & you can deliver it off a web site..
1) check if java is installed on the machine and its version. if java is not there it would prompt a dialog to say: "you need to install java to run myApp" exactly like eclipse.exe does if it does not find java. it would then terminate.
.. Use deployJava.js to ensure a particular minimum version of Java is present, then..
2) if java is there, then effectively run the command javaw -jar app.jar and spawn the process.
..use Java Web Start to launch the app. directly off the web site. JWS also offers many other neat features, and is compatible with any system that supports Java.
精彩评论