PDA

View Full Version : .jar to windows .exe



Diranttt
December 22nd, 2007, 03:08 PM
Hi, I have just recently begun programming in Java, and I want to create an executable file that can be run in windows from a simple double click. I've spent all morning googeling for it, but all I can find are windows programs that I have to pay for.

So I want to know if there is any way I could simply use the command line for converting my .jar file to a .exe file that can be run in windows.

From what I gather after searching for it all day it seems it's not something you're supposed to do, but I just want to send a program I've made to a windows using friend. Is there any other way to do this?

I guess what I'm really wondering is how you after writing and compiling a program can distribute it as a cross platform program that everyone can run.

Thanks in Advance.

sujoy
December 22nd, 2007, 03:10 PM
ya, i was also thinking about the same problem.... please help us out of this

CptPicard
December 22nd, 2007, 03:37 PM
You've got it all backwards.

The whole point of Java is that it's cross-platform because it does NOT produce platform-specific executables such as Windows .exes. Think about it... if you did that, it would not be cross-platform!

If you want to produce Windows .exes you should use something else... or alternatively, I'm pretty sure some Microsoft-"enhanced" Java version compiles into CLI. Don't know about those though.

Java achieves its platform independence through a virtual machine you need to install. After that, if you build your .jar so that it knows which main() to run automatically, you can double-click to run on Windows.

geirha
December 22nd, 2007, 03:46 PM
A common thing to do is create a sh-script that runs it on *nix, and a .bat file that runs it on windows. So just create run.bat containing:
java -jar prog.jar Then the user can double click that bat-file to run the program in windows.

CptPicard
December 22nd, 2007, 04:35 PM
I was under the impression that just double-clicking on X.jar runs java -jar X.jar?

Diranttt
December 22nd, 2007, 06:12 PM
Yeah, as usual I found what I was looking for elsewhere after inquiring on a forum. I haven't tried running a jar-file on windows yet though, because the program won't run on my own computer now, I get Exception in thread "main" java.lang.NoClassDefFoundError whenever I try to run anything at all, even in Net Beans.

tombug
December 22nd, 2007, 08:21 PM
i used to use a think called jshrink to make jar into exe
atleast i think thats what it was called

http://www.e-t.com/jshrink.html

Majorix
December 22nd, 2007, 10:05 PM
If you want to produce Windows .exes you should use something else... or alternatively, I'm pretty sure some Microsoft-"enhanced" Java version compiles into CLI. Don't know about those though.

Microsoft-"enhanced" Java is called C#, and yes, it can be compiled into a .exe. C# also claims to be cross-platform but I have no idea how it could be run under Linux for example if Mono wasn't around.

If you know Java, C# is child's play.

jespdj
December 22nd, 2007, 10:15 PM
As CptPicard said: if you have installed Java the normal way in Windows, then you can just double-click a JAR file and it will run as if you typed "java -jar program.jar" on the command line.

I get Exception in thread "main" java.lang.NoClassDefFoundError whenever I try to run anything at all, even in Net Beans.
That means that your classpath is wrong.

How Classes are Found (http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html)
Setting the class path (http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html)

LaRoza
December 22nd, 2007, 11:19 PM
C# also claims to be cross-platform but I have no idea how it could be run under Linux for example if Mono wasn't around.


It is a standard anyone can implement, just like C. It is up to developers to make the compilers and tools for them. Some languages, like Turing, are not free in that sense.

CptPicard
December 22nd, 2007, 11:34 PM
Microsoft-"enhanced" Java is called C#

Nope, it is not. C# is C#. Microsoft's embrace-and-extend version of Java was called J++ or something... I think it's mostly dead by now.

LaRoza
December 22nd, 2007, 11:36 PM
Nope, it is not. C# is C#. Microsoft's embrace-and-extend version of Java was called J++ or something... I think it's mostly dead by now.

J# actually. It didn't work out. (On further research, it was J++ that was MS's implementation of Java, and MS was sued)

From the one true internet source:


The failure of the MSJVM to pass Sun's compliance tests was a large factor in the initial lawsuit. On January 24, 2001, this suit was settled and Microsoft agreed to pay $1.95 billion and to cease MSJVM distribution[3]. The settlement document outlined that Microsoft also could not advance J++ beyond its mirrored implementation of Java, version 1.1.4. This effectively ended J++ and further updates. As well, the MSJVM had to cease to be distributed and is no longer available for download.

However, due to settlement of outstanding litigating, Microsoft was allowed to further update the MSJVM to fix security holes and any problems relating to the security theater. Microsoft has announced they will cease support for the MSJVM after December 31, 2007[4].

The technology of J++ was eventually recycled, and currently survives, as part of the Microsoft .NET platform and the J# programming language.

Majorix
December 22nd, 2007, 11:39 PM
Nope, it is not. C# is C#. Microsoft's embrace-and-extend version of Java was called J++ or something... I think it's mostly dead by now.

However you can't deny the fact that C# looks like a pretty messed up Java&C++ mixture.

LaRoza
December 22nd, 2007, 11:43 PM
However you can't deny the fact that C# looks like a pretty messed up Java&C++ mixture.

Some would say it is better than Java.


From the one true internet source:


C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg. His previous experience in programming language and framework design (Visual J++, Borland Delphi, Turbo Pascal) can be readily seen in the syntax of the C# language, as well as throughout the Common Language Runtime (CLR) core. In interviews and technical papers he has stated that flaws in most major programming languages (e.g. C++, Java, Delphi, and Smalltalk) drove the fundamentals of the CLR, which, in turn, drove the design of the C# programming language itself. Some argue that C# shares roots in other languages.[2]

CptPicard
December 22nd, 2007, 11:46 PM
However you can't deny the fact that C# looks like a pretty messed up Java&C++ mixture.

I wasn't even trying to deny that C# is quite probably strongly inspired by Java or its flaws. That however was not the point.