Compile Java excutables? How? It’s so confusing!

Well someone made it easy!

1. Download and install this bundled build of GCC/GCJ 3.3 for Windows (MingW) and SWT. Follow the instructions to put into your path it’s bin directory.

2. Create your simple HelloWorld app as

class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World");

3. Navigate to that directory from a command prompt and type:
>gcj –main=HelloWorld -o HelloWorld

4. Now execute your HelloWorld.exe:

It runs! The executable is a little larger then I had hoped (3.5MB), but that beats telling users they need a JVM installed! More about it in this JavaLobby thread. I write many non-GUI utilities and this maybe just the trick for some of them. This originates with the article I linked to earlier at IBMDeveloperWorks, Create native, cross-platform GUI applications, revisited.

3 thoughts on “Compile Java excutables? How? It’s so confusing!

  1. Apparently this sort of thing Just Works in Mac OS X, even to the point of being able to put Java application into the same bundles that native apps use. (A bundle is just a directory ending in .app with the bundle bit set.)

    It’s nice when an OS platform vendor doesn’t have such an antagonistic relationship with its developers’ chosen tools.

Comments are closed.