• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Can you turn java files into an EXE?

GoingUp

Lifer
I have a little game that I wrote for my java class, and I was wondering if I could turn the 4 java files into one exe file for the game.... is that possible? Are there any programs that do that?
 
Originally posted by: Ameesh
Microsoft J++ can do that.

Unfortunately...some would say 😉 j/k 😛

EDIT: Just so this isn't an entirely wasteful post - You could make a batch file and invoke the java.exe program to run your class files instead 🙂
 
yeah j++ can do that, though the exe is just a wrapper, still requires the jvm

i believe symantec made a true native code java compiler, not sure if it's still there.
 
Visual Cafe lets you compile to native Win32. Last time I used it was 4 years ago so maybe they fixed it since then, but it used to have much more memory leaks than java code running under the standard JIT compiler. At least it takes real standard java and isn't near as buggy as J++.
 
Originally posted by: Gobadgrs
So where do I go on the web or elsewhere to get this program to do it?
Static native Java compilers are extremely unpopular. Not only do they fly in the face of the Java platform design, but in practice, they typically lag the current state of the art by years (not months). Furthermore, in testing, they have rarely lived up to claims of better performance. Nowadays, the relative gap between JIT'd Java and very mature C/C++ runtimes is estimated at roughly 2-3 times. Since static Java compilers are not nearly as well developed as C/C++ compilers and runtimes, there is little benefit from going this route.

In the past, TowerJ was a popular, expensive, commercial server-side static Java compiler. GNU's GCJ (part of GCC) is a fledgling open-source project with the best chance of reimplementing Java, but it's currently years behind Java2 1.4. I think the current commercial leader in static Java compilers is something from Excelsior, or something like that. But like I said, static Java compilers are a niche market that's becoming less relevant as time passes (and JVMs increasingly mature).

If your question just has to do with packaging and startup of a client app, then the two standard ways are:
  1. A shell script to call the JVM command. Java client apps can be packaged as JARs that specify the Main-Class as an attribute in the JAR manifest. This simplifies calling the JVM to java -jar MyApp.jar
  2. Java WebStart, a web-based client app bootstrapping technology that's relatively new.
A few vendors offer an ad-hoc technique of building a small .exe wrapper (typically on Windows platforms) that is essentially a native form of the shell script. A couple examples of IDEs that do this were already mentioned; I think Borland JBuilder also provides this facility. You could write the equivalent code in C in fewer than 100 lines of code using the invocation API if you really wanted to. But as mentioned, there's little benefit to this route. It requires extra maintenance, and the JVM would still have to be deployed for it to work. This .exe loader approach is completely different from the static compiler/runtime mentioned above.

Although somewhat primitive, the shell script is still the de facto standard bootstrap approach for the Java platform.
 
The only other way I have seen is to wrap an NT service runner around the java application. The Java app is still a java application running with a JVM, but it is now capable of running as a service.
 
J++ is the "easy" way to do it for a windows application.

Alternatives, create a VB/C wrapping executable. I use one and it works quite nicely, a VB6 wrapper for windows users and a C version for Linux. OS X will automatically launch a properly created jar file so that makes things easy there.

The relevant line from the VB wrapper:

x = Shell("javaw -jar KilCli.jar", vbNormalFocus)

The C version of that same idea (although this relies on a system variable, you get the idea):

#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
int i;
i = system ("cd $KILCLIPATH;java -jar KilCli.jar");
return 0;
}
 
Well, if you just want "double-click" ability, you could create a batch file. Something like

@echo off
PATH="C:\path\to\java\bin"
java C:\path\to\java\program

and save it as Program.bat

I'm not sure about the PATH thing, I'm not sure if there should be quotes or not.
 
Back
Top