14

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:

  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.
  2. if java is there, then effectively run the command javaw -jar app.jar and spawn the process.

any idea ?

chacko
  • 5,004
  • 9
  • 31
  • 39
  • Couldn't you do this easier with a simple batch script that checks java -version and if a useful answer is achieved you can run your char? – RoflcoptrException Apr 01 '11 at 10:30
  • Yes, i could use a batch. The point is to make it simple for users who don't care about java, batches and so on. They are used to click on 'exe' files and that's about it. – chacko Apr 01 '11 at 10:56
  • There are tools out there to convert batch files to exe files...... – Adam Burley Nov 28 '14 at 16:08

5 Answers5

7

JSmooth does exactly that.

jmg
  • 7,308
  • 1
  • 18
  • 22
3

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.

javanna
  • 59,145
  • 14
  • 144
  • 125
0

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?

Community
  • 1
  • 1
  • 1
    chacko needs an exe file. Users feel more comfortable with an exe file rather than some strange executable file ending with .jar or .bat for instance. – Stephan Apr 01 '11 at 10:37
  • Yes that's true, I just want to show an alternative. (However you could use an bat to exe wrapper ;) ) –  Apr 01 '11 at 10:38
  • Don't forget to put your exe wrapper inside a nice install program and ultimately to wrap the install programm in some archive file ^^ – Stephan Apr 01 '11 at 11:04
0

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.

chacko
  • 5,004
  • 9
  • 31
  • 39
-1

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.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433