[java] Java applet to Windows exe?

Started by
9 comments, last by archetypist 21 years, 7 months ago
Okay, this may be silly; I feel certain I should know the answer to this. Anyway, my question is: if I have a java applet (the code, of course), how can I turn this into a free-standing windows exe? Thanks in advance.
Mike SellersOnline Alchemy: Fire + Structure = Transformation
Advertisement
There is no easy general way to do it, especially if you are using Java GUI components. You might want to check out JET or GCJ though.
It wouldn''t really be ''free standing'', but you could always create a batch file (.bat) that has the following contents:
start javaw -cp //My/Games/Location MyGame 

That would only work for Applications, you could use AppletViewer... but I don''t remember the command to start something with that.
If you don''t really really need an exe, you can make an executable jar file and then configure windows to execute jar files with a certain command everytime you double click it.

If you want a .exe file, then you can use the Java Native Interface. Basically, on the native (C++/C or whatever) side, you instantiate a JVM and then tell it to run the main method for whatever java class you want. Of course, you''ll still have to have the class/jar files around, but at least it''s an executable.

I''ve tried both ways. The first method should suitable, but the second method looks more professional for some reason. It requires more code, but it''s just another solution.

If you want to find out how to do this, read the tutorials on JNI at javasoft.com. You''ll find all you need to know to do this.
quote:Original post by davidko


If you want a .exe file, then you can use the Java Native Interface. Basically, on the native (C++/C or whatever) side, you instantiate a JVM and then tell it to run the main method for whatever java class you want. Of course, you''ll still have to have the class/jar files around, but at least it''s an executable.



This isn''t JNI. This is calling a Java applet/application from a native app. JNI is the ability to (more or less) do the opposite, i.e. to call native code from a Java application. Some of the reasons to use JNI include the need to interface with legacy systems, and to improve performance (but this is less these days).

"Linux is not about free software, it is about community," -- Steve Balmer, Microsoft Chief Executive.
quote:Original post by Viro
This isn''t JNI. This is calling a Java applet/application from a native app. JNI is the ability to (more or less) do the opposite, i.e. to call native code from a Java application. Some of the reasons to use JNI include the need to interface with legacy systems, and to improve performance (but this is less these days).



JNI goes both directions. I believe he was talking about using the code for embedding the JVM into a C program. That is part of the JNI library... The invocation library, I believe. It might not be the most sophisticated use of the JNI system, but when you have to #include <jni.h> to get the thing to work, it''s JNI.
Thanks for the replies.

FWIW, the applet in question is written in Java 1.1, and contains no Java GUI elements (such as buttons I mean; it does use Canvases and such).

If there''s any relatively direct way to turn this into an actual .exe, please let me know!

Thanks!
Mike SellersOnline Alchemy: Fire + Structure = Transformation
The second poster directed you to JET or GCJ. Those are AFAIK the most direct way of making an EXE of a java program.
"Linux is not about free software, it is about community," -- Steve Balmer, Microsoft Chief Executive.
First, if you have an applet, you might have to change the source to make it a stand alone program, this might be as easy as to add a main function or a lot harder if there is a lot of code that references the browser. Of course the applet itself might already been coded to work stand alone.
As for making a windows exe out of a java program, there are some programs out there that do exactly that, among them Excelsior JET (which is not free, but has a free Personal Edition version) that generates a full exe, no libraries hanging around, and Native J (no freebe here, 80 bucks instead) that generates a start-up wrapper for any java program.
Others are IBM Java Developer Kit 1.3.0 for Windows (I think it''s free), and of course Jove, if you have lots and lots of money.

A lot of this stuff can be found looking around the web, the IBM DeveloperWorks website is a great reference and learning site for Java in general.

D-

-----------
Érdely!
-----------Érdely!
arche, go here:
http://www.math.uwaterloo.ca/~elterra/Generating%20.exe%20from%20.class.html

I have used jexegen. It is easy and does exactly what you need.

This topic is closed to new replies.

Advertisement