This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I convert my Java program to an .exe file?
How to make executable program in java?
You don't really need to, there are a number of other options available:
As Philip suggested you can use an executable jar file. See http://www.ibm.com/developerworks/library/j-jar/index.html
You can build on top of a framework that already has its own launcher such as Eclipse. See http://wiki.eclipse.org/index.php/Rich_Client_Platform
You can use a technology such as Java web start to launch your app from a browser. See http://en.wikipedia.org/wiki/Java_Web_Start (or just package your app as an applet)
probably this may help you
http://www.javacoffeebreak.com/faq/faq0042.html
there he talks about nice tool called Java2Exe which serves your purpose
The common way is the following:
compile your class files: javac *.class
create a jar file (it's basically a .zip-file):
echo Main-Class: MyMainClassName > manifest.txt
jar cvfm MyOwnJarfile.jar manifest.txt *.class
create a .bat-script (or sh script if your are on unix):
echo java -jar MyOwnJarfile.jar > start.bat
Double-Click on start.bat ;-)
Related
This question already has answers here:
How does a jar file get executed? Do the classes get extracted somewhere?
(2 answers)
Closed 3 years ago.
Take a standalone executable jar file for example, in which we generate from our application with all the dependencies etc. My understanding is that this file contains all the classes etc. compressed.
When we execute this jar file via the command line as follows java -jar myjar.jar , is this being decompressed on the fly? Does the interpreter first decompress everything before executing or how does this work exactly?
We already have one answer to similar question here :
How does a jar file get executed? Do the classes get extracted somewhere?
The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files.This functionality is also available to you in the standard library, see the JarFile for more information.
So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.
We can also check if the jar gets extracted or not by executing the command "java -jar myjar.jar" and check the folder where jar is located if there is any extraction while executing the program.
This question already has an answer here:
How do I compile a java file that has jar dependencies?
(1 answer)
Closed 8 years ago.
Background: Running on an ec2 instance not eclipse.
I have a java program that has external Jar dependencies. I want to create an executable jar file for this java program (being able to package the external jar files into this jar file would be icing on the cake)
The problem is that for me to use the java cf or cmf command I need to have a .class file. But, when I try javac HKP.java it throws a bunch of errors saying "xyz does not exist or cannot recognize symbol" which I'm guessing is because it has no idea about the external jar dependencies.
I have tried doing javac -sourcepath /home/ec2-user/apps/HKP/lib/ HKP.java, but it throws the exact same errors as before.
EDIT I have tried javac -classpath file1.jar, file2.jar, file3.jar HKP.java -I have also tried this with ";" in between. both return errors saying -bash file2.jar command not found, so instead of continuing the argument, bash is recognizing the multiple jar files as commands.This is the initial problem I had that caused me to post here.
Any help is much appreciated. Thank you!
If you want to compile a java source file into a class, you need to provide all classes which are used in that code on the classpath of the compiler.
If the classes come from (already compiled) external JARs, you typically do that by specifying javac -classpath with a list of JAR files, separated by : (on Linux). But you should really think about using an IDE or at least a maven build file (Which has the benefit, it can even download those JARs for you).
Both (Eclipse IDE and Maven build system) can also generate a ueber-jar with the external classes in there for easy execution.
try to Add the path in system variable and restart your computer.
This question already has answers here:
How to make Java program installable?
(6 answers)
Closed 9 years ago.
I made some programs in java but I don't know what I should do afterwards finalizing it for the end user. all I have is a bunch of .class and .java files in a directory and I have no idea how to distribute it to the user. Isn't java supposed to work like a normal program where I install it through a self-extracting file or InstallShield like how pc games install their programs? Thank you.
I've read on deployment but mostly I saw was how to package it into a .jar file. I'm not sure how that works but the user would most likely not be able to know what to do with a package file unless I include detailed instructions on how to operate it. I was hoping there would be a way that I install the entire java program with a .exe file like a normal program does and it will load up into a specified directory and create start menu/desktop shortcuts for the user to use.
Thank you in advance.
.jar Files are runnable on each Plattform. That's the advantage of java. So you can roll out the .jar or you can run it into an Java-applet. Or you build an .exe launcher...
Like this:
https://stackoverflow.com/a/15409917/2617699
Export it into an executable jar using eclipse. The you can create an exe using Launch4j or any similar software.
This question already has answers here:
How do I create a ZIP file in Java?
(2 answers)
Closed 9 years ago.
Is it possible to compile class file to jar file not using jar -cvf options.
I want to compile jar files by source code.
Cant somebody show me some example codes
A JAR simply is a ZIP file.
While I am not quite what you are trying to achieve, I can give you these hints:
Compiling: javac Hello.java
Creating a JAR: zip Hello.jar Hello.class
If you want to have a JAR containing your sources, you could as well run the above command with: zip Hello.jar Hello.java
Also note that, if you are using a build tool like for example maven, there are various plugins for suchs tasks such as 'assembly' (for maven).
There was a program that I used that made runnable .jar files.. All the ones I'm finding now are ones that make .exe files.. I remember it also has the option to make the file a .sh script as well. Anyone knows its name? I've been searching for hours with no avail :/
The command line
java -jar file.jar
Will run your jar file if it has a Main-Class defined as explained here.
You can use that command in a shell script.
You can create a runnable jar using NetBeans IDE or Eclipse IDE by just providing the main class to run. Rest of the things it will take automatically. That class must be having a main() method in it. Then you can run that jar file using java -jar yourjarfile.jar
Do you mean actually coding java and then compiling to .jar? If you do try
eclipse code editor
I used eclipse to make minecraft mods. It will work if you want to make .jar programs.
If you want to have a jar that you can execute using the usual syntax ./app.jar (instead of java -jar), here is a post explaining the process: how to create executable jars.
Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it "executable".
Here is a simple example of the process:
# Append a basic launcher script to the jar
cat \
<(echo '#!/bin/sh')\
<(echo 'exec java -jar $0 "$#"')\
<(echo 'exit 0')\
original.jar > executable.jar
# Make the new jar executable
chmod +x executable.jar
With this, you can now run ./executable.jar instead of java -jar original.jar. This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.