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?
Ernest Friedman-Hill
author and iconoclast
Marshal
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.
Now, as soon as I learn enough to be dangerous, I will research this.
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
posted
0
In addition to executable JARs, also be sure to use javaw.exe instead of java.exe. What's the difference? javaw.exe suppresses the command prompt -- giving you the professional look you want.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Tony Carolla
Greenhorn
Joined: Dec 05, 2005
Posts: 13
posted
0
Hmmm... I am trying to run HelloWorld.class, which contains:
public class HelloWorld { public static void main(String [] args) { System.out.println("Hello World!"); } }
It compiles, runs using "java HelloWorld", but if I type in "javaw HelloWorld", nothing happens. No error, no window opens.
I am going to take a guess that I need to be able to create windows/buttons/gui stuff before javaw will work?
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
posted
0
That's it.
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!)
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.