Command line tool to convert a jar to an executable? [duplicate] - java

This question already has answers here:
How can I convert a JAR file to an EXE file?
(9 answers)
Closed 10 years ago.
I can convert a Java .class file into a .jar file by the following command:
jar cvf Hello.jar Hello.class
Now I want to convert the .jar to a Windows executable (.exe).
Is there any similar command or any command line tool to do this?
I am developing an automatic tool to compile the .class file to an .exe without any human intervention so GUI-based tools will not work.

There are several options out there :
Jar2Exe
Excelsior JET
Executor
JSmooth
GCJ
JCGO
Launch4J
JexePack
The last one(JexePack) is maybe the more closer to your needs since it is a command line tool :
JexePack is a command line tool (great for automated scripting) that
allows you to package your Java application (class files), optionally
along with its resources (like GIF/JPG/TXT/etc), into a single
compressed 32-bit Windows EXE, which runs using Sun's Java Runtime
Environment. Both console and windowed applications are supported.

I've always used Launch4J. Easy to add to an Ant or shell script. There is a GUI to facilitate building the config file (if you need it), then reference the config file in the script.

Have a look at JSmooth. Bonus: There is also a maven plugin for it.
Update: To run as command line see the command line reference manual.

Related

Creating a Linux executable file for my Java application Jar file

I found that Packr is the best tool to use for creating an executable file for my Java application on Linux. The executable works perfectly on Linux, but i have a question about this tool:
The tool forces me to embed JRE with the output folder causing big output size for my application. Can i create the executable without embedding JRE with it?
If you are using java 9 or above you can use jlink to create an image that only contains the required jre modules and therefore will likely give you a smaller distributable. There's a tutorial here

Running a class that relies on Jar file in terminal

For my intro computer science class they recommend using eclipse as an IDE. I have used vim in the past and would prefer using it. There are two .jar files that the programs we create rely off of, because it is an intro class and we are not using java's main class functionality.
Right now we download the two .jar files and then use the Eclipse IDE build path function to link the .jar files with our code. Then when we run on Eclipse IDE it works perfectly fine.
How would I do this in ubuntu terminal? Thank you!
TLDR;
Intro comp sci class wants us to use eclipse, I want to use vim. How do you build path for a jar file to work with my class code in the ubuntu terminal.
Looked at this link and did not work
Java: how to import a jar file from command line
Update of image
You specify the jar files with a CLASSPATH, either using a CLASSPATH environment variable
export CLASSPATH="a.jar:b.jar"
java com.mypackage.MyClass
or on the command line with -cp like
java -cp a.jar:b.jar com.mypackage.MyClass
Include your jar dependencies while executing from command line.
java -cp tester.jar lab1

How to create executable .exe file from .jar file? [duplicate]

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed 6 years ago.
I've created an app using netbeans IDE but it is in .jar format.How do I convert it into .exe to use on individual system ?
many responses here:
Compiling a java program into an executable
JSmooth .exe wrapper
JarToExe 1.8
Executor
Advanced Installer for Java - tutorial for Java applications
GCJ
Launch4J: http://launch4j.sourceforge.net/
If you need to just create a runnable file of your application, the JAR should be enough to do the job. You can export it as an executable jar with the manifest file and run it just by double cliking it.
Still if you require an exe, then you can use Launch4J. To create an exe, create jar file for your application using your IDE with proper MANIFEST file packaged inside. Then launch Launch4J and select your jar file and you should be able to create an exe easily.
For more details, take a look at this link here
You can use launch4j this can make jar an exe

How to make a Java program be opened by default with Java, on any computer

When I send Java games I created to friends, the JAR file I send them often looks like a RAR file to them. This is because Windows on their computers thinks this file should be opened by WinRar.
They have JRE on their computers, but the default on Windows is that the file they recieve should be opened by WinRar.
The people I send my program can't be expected to guess, that what they need to do is specifically tell Windows to open the file with Java.
Is there a way to make it so that a JAR file I send to somebody, will be opened on his/her computer by default using the JRE?
Thanks a lot
You can consider adding a BATCH script.
Something like java -jar YourJarName.jar
You will need two of them - for unix and windows:
Windows start.bat:
java -jar YourJarName.jar
Unix start.sh:
#!/bin/bash
java -jar YourJarName.jar
You could use a tool such as Launch4J to wrap the JAR file into an executable.
You can convert your JAR file to executable file using Java Launcher.
OR
As #lan Roberts answer You can use Launch4j to wrap your JAR to executable. You can download it from this.

Distributing a Java console program

I have created a Java console application using Netbeans. In the Netbeans dist directory I have the class file of the project. Now I need to give the executable files to someone else
who will run them on another PC.
Which file I should send? How can he run them on his PC? Is there any way to create an exe type file?
Both PCs have the JDK installed.
Build a jar file with a main class specified in it.
If he has Java installed and .jar is associated with that, he should be able to just double-click on it.
Alternatively from a command line he'd be able to run:
java -jar program.jar
There are programs around to create executable wrappers around this, but a jar file is a simpler solution in terms of packaging - it's worth trying that to start with.
In additon to Jons answer:
If you have a runnable jar to start with, it is frequently much easier to package it up in an EXE file. If you have the need search Stackoverflow for JSmooth and one-jar.
NetBeans actually answers your question. If I do a Clean/Build, the output says:
To run this application from the command line without Ant, try:
java -jar "insert_your_project_name_here.jar"
theres a handy page about this here:
java tools tutorial
It describes creating jar files a little further down the page
You can go to run menu and select clean and build project or shift+f11 after this go to dist folder in project folder and use .jar file and run that by hint say in over .

Categories