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
Related
This question already has answers here:
How to decompile a whole Jar file? [closed]
(8 answers)
Closed 4 years ago.
I exported a project from Eclipse and then I tried to run'it in my machine and I couldn't. I readed some articles and I realized that I exported the program on a wrong way, (I'm using Eclipse as mi IDE) Eclipse gives you the option to export the project whit the (Runnable.JAR) option and the (.JAR extension), both are different. I thought the right way It was .JAR extension, but It wasn't, I tried with another project the (Runnable.JAR) and It worked. but I erased my priory project from the workspace of Eclipse(the one the I imported with the .JAR extension),and I've tried to import the program with the .JAR extension and it works but it just appear the compiled file, I can't run it. How can I convert the (.JAR to Runnable.JAR) or at least use it?
From what I can tell the only options you have are to either attempt to recover the deleted workspace, decompile your code, or restart the project.
To decompile your code I suggest either using this, or this, both should do what you want, but I've always had good luck with the 2nd option. As long as you haven't obfuscated your code, this should work correctly.
This question already has answers here:
Whats best way to package a Java Application with lots of dependencies?
(7 answers)
Executable Jar with depedencies
(5 answers)
Closed 7 years ago.
I made my first application with Java in Eclipse now I need to repackage or create an executable file file from that project. I used a lot of external jar libraries that I would like to export whit the project. Any solution is welcome.
I suggest to use apache maven to make a fat jar in conjunction with the launch4j maven plugin to make an self-contained exe (i.e. a wrapper for the jar).
you can make a executable jar file of that project. And then make a .bat file. From that .bat file you can invoke that executable jar.
Eclipse will pack you yourprojectname.jar file, which is executable file. So, in order to run it you may just run in command line (a.k.a cmd) java -jar path/to/your/project.jar. And of course it is more easier to run it with script. There are .bat files which are something like .bash scripts in linux/unix
Right click on your Eclipse project in ProjectExplorer
Export...
Java\Runnable jar file
On dialog Runnable JAR file export
4.1. Choose the main() method you need to start from the popup "Launch configuration"
4.2. Specify the output jar like: d:\dest.jar
4.3. "Finish'
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Corrupt jar file
I made a game in Eclipse and packaged all the class files in test.jar. When I attempt to run it, it gives me the error:
Error: invalid or corrupted jar file.
I opened the .jar file using Winrar, and everything is in there.
I have looked for a similar question on Stack OverFlow, but didn't find any. Can you explain to me how I can solve this error?
FOR EVERYONE WITH THIS PROBLEM ,SOLUTION:
Go to file, export, export as a Runnable Jar, Select your main class, finish.
If you want to run your program in cmd, create a new textfile, and type java -jar project.jar with project = name of your program.
Save this as Run.bat
then open the Run.bat, it will automatically open project.jar
Thats it, it worked for me!
How you place your classes to tar.jar? A valid jar file must follow some rules it requires. You'd best generate them by your Eclipse tools. click "export" -> "jar" and select the right entry of your game. Good Luck.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I convert my java program to an .exe file ?
Hello,
I coded a java project using Eclipse software. Now i need to convert that project to .exe file. I export that project and hence converted to jar file.
when i double click on it, it shows "failed to load Main-class attribute from 'path'". So unzipped it and looked into the MANIFEST. mf, there it has only version.
I also used JartoExe software and converted to exe file. It shows a cmd prompt like file but when i click it, i am just getting a flash of that window. Its not opening.
Please help me to convert the jar to exe file!!
Thanks in advance!
Take a look at this article: http://introcs.cs.princeton.edu/85application/jar/jar.html
You basically have to define what gets executed in the manifest and then if you want to your program under windows, you can either associate the jar type to java.exe or create a .bat file that starts the jar appropriately.
While exporting to jar file you need to provide the main class name, which is the entry point to your program.Once you do this, manifest file in jar will have entry for it and that will allow you to run it by double clicking on the jar.
When you choose Export from eclipse, one of the dialogs asks you what the main class is. If you specify it then when you double click on the jar it will launch the app.
Use JEXECreator 1.9.3, it is very good. It gives you two options to run your program: either using the console or the GUI
The easiest way to do so is to have a eclipse plugin "fat.jar" and add it to your eclipse
next you will get an option to build fat jar when you right click on your project.
Do restart of your eclipse after installing fat jar..
wow...
very easy...
http://www.ej-technologies.com/products/exe4j/overview.html
I once use this, it's good. But the free version has some kind of ads flash screen, if I'm not wrong.