views:

733

answers:

4

Suppose I want to distribute a Java application.

Suppose I want to distribute it as a single executable. I could easily build a .jar with both the application and all its external dependencies in a single file (with some Ant hacking).

Now suppose I want to distribute it as an .exe file on Windows. That's easy enough, given the nice tools out there (such as Launch4j and the likes).

But suppose now that I also don't want to depend on the end user having the right JRE (or any JRE at all for that matter) installed. I want to distribute a JRE with my app, and my app should run on this JRE. It's easy enough to create a Windows installer executable, and embed a folder with all necessary JRE files in it. But then I'm distributing an installer and not a single-file app.

Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?

+2  A: 

Quite a few options around, commercially this is very good:

http://www.excelsior-usa.com/jet.html

There are two key open source options GCJ and VMKit

http://gcc.gnu.org/java/ and http://vmkit.llvm.org/

Other more prolonged paths would include IKVM.NET:

http://www.ikvm.net/

Which is a .NET JVM which can be statically compiled to an EXE

metismo
Excelsior JET looks kind of interesting. Will give it a closer look. I'm afraid I don't trust GCJ enough, but I could give it a try. Re: VMKit, wouldn't a JRE implementation for CLI require .NET?
perp
VMKit is both a .net and JVM solution in compilation terms, for the JVM side I think it merges in GNU Classpath; but its in beta for the moment, so I think its a little off commercial usage. (The only thing I found limiting with Excelsior JET was no MacOSX support.)
metismo
+1  A: 

Is there a way to embed both the application, and a JRE, into an .exe file acting as the application launcher (and not as an installer)?

If a commercial tool is ok for you, install4j solves this problem very smoothly (see its "Features" page). It can generate both application launchers and installers.

I'd hate to repeat myself too much, so check e.g. this earlier answer where I plugged it (as installer builder, but it doesn't make much difference here).

Summary / bottom line: install4j can create native .exe launchers that absolutely do not depend on a pre-installed JRE (or any other specific libs), and it offers flexible options for bundling (and detecting) JREs.

Jonik
I've downloaded a trial version, but I can't really figure out how to make it do what I want. All I can make it do is create an installer?
perp
Jonik
I just realised that the company behind install4j also has a product called **exe4j** specifically for creating launchers: http://www.ej-technologies.com/products/exe4j/overview.html. I'm not 100% right now if exe4j can do something that install4j doesn't – AFAIK both can create exe launchers with bundled JRE.
Jonik
A: 

JSmooth can do this according to the documentation. I have only tried it without an embedded JRE, but been very satisfied. It is scriptable with ant and we build on Linux.

http://jsmooth.sourceforge.net/features.php

Thorbjørn Ravn Andersen
Where does it say that? I browsed through it, and all I can see mentioned is that it supports a "bundled" JRE, which isn't the same thing. All I could see on the subject was what's mentioned in section 3.4.2 in the manual...
perp
"Sometimes it's more convenient to bundle a JRE with your application. JSmooth can deal with that too, you just need to define in which folder the JRE is expected. It falls back nicely to a standard JVM search if the JRE is not where it should be." I read this as being an unpacked JRE, not an installer.
Thorbjørn Ravn Andersen
Yes, exactly, the .exe can look for a JRE in a specified folder, but I already knew that was possible with several different tools. I'm wondering if there's a solution where the JRE can be embedded *inside the application binary itself*, which is different. So not "bundle with" but "embed in". :-)
perp