How to turn a JAR file to an EXE file manually? [duplicate] - java

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed 9 years ago.
Well I have made a few games and programs in java, and I was wondering, HOW DO YOU MAKE THIS EXE? I have been looking around google for the answer and I couldn't find any program or website that helped. So I want to make it EXE myself, manually. I have already tried JSmooth, and that didn't work.

You need to learn about creating an executable jar. Once you create that, you can simply run it by double clicking on that. Here is a tutorial to help you with that:
http://www.mkyong.com/java/how-to-make-an-executable-jar-file/
If you want to create a batch/cmd/sh script then you can put your java command in that script to invoke your main class.
A sample batch script taken from a related post(How to run java application by .bat file):
#ECHO OFF
set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;path/to/needed/jars/my.jar
%JAVA_HOME%\bin\java ro.my.class.MyClass
On the same lines, you can write a shell script on linux/unix.

Java now ships with a tool that can convert your application into an executable. The documentation is written for JavaFX applications. I think you should be able to use it for any java application though.
Check out this article discussing how to deploy a JavaFX Application:
http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm
Using this tool requires that you install Inno5 Setup (for creating an exe) or WiX (for creating an msi) or both if you want to create and deploy both an exe and an msi.
If this tool that ships with Java doesn't work for you there are projects such as install4j that convert your project to an exe. See http://www.ej-technologies.com/products/install4j/overview.html.

Related

Java exe or binaries creation [duplicate]

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed last year.
Is there a way to create exe files or binaries in java? I've been only able to create java.class files after compiling the code, but I was wondering whether it is possible to create a normal program in a binary or a exe format that I could run without using command java File every time I want to run a program.
The suggested Executable jar files still require a java interpreter to be installed on the system. And as mentioned above, compiling directly into a Windows Executable looses platform independence. Yet it may be desireable to get a more native look and feel during application installation.
For this Oracle/the Java community created JPackage. It wraps your application together with the required JVM such that the whole package can be treated like a native application - regardless whether you want to run on Linux, MacOS or Windows.
You can package all the class files into a .jar file. This .jar file is executable by running java -jar <file>.jar, but most operating systems will allow you, when Java is installed, to double click on the jar file and execute it in this way.
Most build systems (such as maven and gradle) will make it easy for you to create such a file. If you have external dependencies (other jar files), you will need to create a "fat jar" that also includes those dependencies; there are plugins for those build systems to create fat jars.
You can use Launch4J to make an exe file, here you can find more info - https://youtu.be/jPKxqc8Zg-0

I have developed a java desktop application for windows i need to make exe file [duplicate]

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed 5 years ago.
I have developed a java desktop application for windows i need to make exe file, I don't know procedures to develop exe from my project
Right-click the desired project and choose Package as > EXE Installer from the context menu (https://netbeans.org/kb/docs/java/native_pkg.html#instse)
Note: The IDE creates an EXE installer only if Inno Setup is installed and added to the system Path variable (https://netbeans.org/kb/docs/java/native_pkg.html#tool)
When the EXE installer is ready, it is placed in the /dist/bundles/ directory.
This answer extends #pruntlar answer.
Since you will be making Windows applications I suggest you also look into Windows Installer Package(MSI). The Netbean link #pruntlar provided should also cover this topic. The tools needed are available free here: http://wixtoolset.org/
Why not launch4j.
It's written in Java and it can create a .exe file that you run your jar file or it can create a .exe file with your jar file inside it.

How can you make a Java app executable? [duplicate]

This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 8 years ago.
I have written a simple little program that opens a JFrame window every time you click a button. Although each time I want to run it I have to go into my IDE(NetBeans) and run it from there. Would I be able to make a .jar thing and it will run like that? How do you make it executable. Should I use a batch or bash file to run it?
In Netbeans you can right click on your project in the Project Explorer and then select clean and build.
After that you can find the .jar under dist, which is located in your project folder.
You're looking to make a jar file. If you're on windows/x whatever graphical interface, you simply run it like any other executable. If not then you can run it from the command line like any other program.
To make a jar from the command line as per the Oracle documentation http://docs.oracle.com/javase/tutorial/deployment/jar/build.html:
jar cf jar-file-name input-file(s)
NetBeans also has an interface to turn your project into a .jar if I recall correctly.
Edit: Yes it does have an interface. A quick search of the site yields:
How to create a Jar file in Netbeans

How can I create a command line application in Java? [duplicate]

This question already has answers here:
How to create a Java application which can be run by a click?
(8 answers)
Closed 9 years ago.
I am in the process of writing a command line tool which should work on all popular platforms (Windows, Mac & Linux). I was thinking of writing it in golang because it can generate statically compiled binaries and works on all the above said platforms. Before I take the decision, I need to evaluate Java and see if it can do this.
I'm wondering is it possible to create first class command line programs in Java? AFAIK, a Java program needs to be started like
java -cp classpath MyApp
Now I need to wrap this in a shell script to improve the experience. Something like,
#!/bin/sh
java -cp classpath MyApp $#
Now user can do:
myapp --arg1 value --arg2 value
The problem is this approach is not cross-platform. On Windows, I need to write a batch file to do this.
I'm not sure if this is the right way to do in Java. Is there a better way to handle this problem?
the solution you posted (platform specific script files invoking java) is indeed the easiest and quickest to implement. if thats not enough for your needs there are several solutions which provide better usability:
executable jar files. basically by stating your main class in a MANIFEST.MF entry the file becomes executable by double clicking on some platforms (windows definitely, the rest im not certain). note that this requires a properly installed JRE on the machine.
service wrappers. there are 3rd party products that will wrap your java application in a native executable and allow your application to "feel" like a native app. the most commonly used one is the tanuki service wrapper but there are others (launch4j is an open source alternative that fits your set of required operating systems)
EDIT - more options in a related SO question here
To work with command line arguments comfortably, you can use Apache CLI. It parses arguments and print a list of them if some are missing. In java projects it's always OK to have *.bat and *.sh files both in the bin folder. What confuses you in this approach? Have a look at Ant or Maven projects for example.
I would probably suggest to use Maven, It has a concept called "maven spring shell" which would be easy to develop. You indeed need to write .bat and .sh for windows and linux, but it is more of a configuration type. Would be easier to package.
The following link would help you developing spring shell applications

how can I create executable file for the program written on Java?

everyone, how can I create executable file for the program written on Java in Eclipse Helios? I mean to create small icon to be able start program only by double-clicking on its icon, thanks in advance
edited
I mean executable for Windows
Export .jar in eclipse. (how to)
Use JSmooth (info) to make an .exe file. (how to)
Here is a tutorial that shows you how to make a jar file from eclipse.
If Java is installed on the computer, you can execute your application by doubleclicking the jar file:
http://ecs.victoria.ac.nz/Courses/COMP205_2009T1/TutorialEclipseExportToJar
You didn't mention what platform you are using. There are 2 ways I can think of.
The easiest way is for you to create a *.bat file (in Windows) that contains the java YourApp command line.
If you want to create a more fancy installer and executable, you can use NSIS script to do so. Since you are using eclipse, consider trying EclipseNSIS to generate the NSIS script, which is much faster and easier than writing it yourself from ground up.
The best answer for this situation is to launch the app. using Java Web Start. JWS can not only create desktop and start menu launch items, but provides automatic updates, cross-platform compatibility and much more.
Create a 1-line metafile to specify which class the JVM should look for to start with the main(String[]) method.
Run the command jar cmf [metafileName] [jarfileName] [classfiles] [img/txtDirectories]
You have an executable jar file - type in "java -jar jarfileName" or, directly "jarfileName" at your prompt. On windows, you can also double click on the jar file logo/name to get it started.
Good wishes, - M.S.
PS: Here is the link to a more detailed tutorial:
http://csdl.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html

Categories

Resources