I am studying Java, and I finally bought the HeadFirst learning java book. After being thoroughly confused and overwhelmed by the Weekend Crash Course book (Whew what a weekend), I am finally learning it the right way.
I have not read the whole book yet (I just got into final and static modifiers), but so far I see no mention of making windows .EXE files out of java applications. Is this possible? I know that the JVM runs .Class files, and there is a way to run .Class files as browser applets (I'm not there yet), but is there any way to make an .EXE that I can distribute?
You really, really don't want to do that. Macs can't run *.exe files. Linux, Solaris, HP/UX, AIX... lots of machines can't run *.exe files -- but they can run Java programs if that Java program is packaged as a JAR file -- a Java ARchive containing just the class files. Turning Java code into an *.exe negates one of Java's advantages. You shut out some of your audience needlessly by doing this.
That said -- there are products which do this. Some of them produce Windows installers which then install the *.class files and a Java runtime; others actually produce a *.exe that the user can run directly.
Originally posted by Ernest Friedman-Hill: You really, really don't want to do that. Macs can't run *.exe files. Linux, Solaris, HP/UX, AIX... lots of machines can't run *.exe files -- but they can run Java programs if that Java program is packaged as a JAR file -- a Java ARchive containing just the class files. Turning Java code into an *.exe negates one of Java's advantages. You shut out some of your audience needlessly by doing this.
You are right. I am planning on using several different platforms also (IBM iSeries, PocketPC), and for these, .Class files are fine.
But for my friends that have Windows, I want to distribute the applications to them, and web delivery via an applet might not be the best way. Maybe I haven't learned enough yet, but it seems that, if you associate .Class files to the appropriate Java.exe application, you get a command window, much like a .bat file. I was going for a more 'professional' look -- perhaps a window that pops up, without the command window. Is there a way to do this, that I just haven't learned yet? I want to stick to Java, and possibly not rely on third-party products (which would add yet another layer where things could go wrong).
In general, I think executable JARs are really what you should go with. Depending on your needs, you might also want to consider a web version of your application since these require no installation at all, just a web browser and an internet connection.
Since javaw has no command prompt, you never saw the println. This means that it's not just a good idea to use a logger (like log4j) with javaw; it's almost a necessity. (You won't see debug statements if they're sent to System.out.println, since you can't see System.out!)
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.