• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EXE

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

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.
 
Tony Carolla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible, although with certain limits. I recommend this article on the subject:

http://www.excelsior-usa.com/articles/java-to-exe.html

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.
 
Tony Carolla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! That was exactly what I was looking for!

Now, as soon as I learn enough to be dangerous, I will research this.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tony Carolla
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!)
 
reply
    Bookmark Topic Watch Topic
  • New Topic