I want to create .exe file for my java project and give it to my friend. I wrote my project in eclipse and it uses sqlite. I don't know how to make a .exe file that can be run in other PCs.
Can any one help?
P.S:I saw this link but it is not useful for me!
Create .jar of an eclipse project that uses Sqlite DB
.exe is a creature of Windows.
To run a Java program, you typically:
Create a .jar file (the "native" Java library format)
Write a DOS/Windows .bat file (or, equivalently, Linux shell script) to run your Java program (using the Java .jar file)
Optionally, create some easy-to-use mechanism for the end user to download the Java JRE (if it's not already installed on their PC).
Your .bat file can be as simple as this:
start javaw -jar myjarfile.jar
Have you considered creating Runnable jar from eclipse.
In eclipse, go to File > Export > Java > Runnable Jar.
There you ll find some options and you can use what suits you. The jar created should be able to run all by itself (obviously it needs the java run time).
Try this out.
I would recommend using a bat file. You can make a double clickable jar file, but I feel that is sometimes restrictive and not intuitive.
Not many end-users know that a jar file is double clickable.
You need to make sure the jar file has a main class and classpath defined. The classpath section in the jar file sometimes causes issues. Like you cannot reference a file or path on the file system. Only files or folders that can be relatively referenced from the location of the jar file.
For windows users, you cannot easily make an exe file from a jar file. There are methods like using jsmooth, that will wrap your jar file into an exe file (bloating the exe file in the process).
The easiest way is to create a bat file. You can easily convert a bat file into an exe and make the exe file have an icon and everything. Link to a converter here:
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
First create an executable jar file by clicking on File menu, then export, and then select runnable jar file.
Then select main class and click ok - the jar file will be created.
After that use Launch4j application to create .exe. Launch4j is the best option for creating an exe file.
Then use Inno Setup Creater to create an installer and it is done.
Related
I've written a few java applications (desktop, no browser involved) for friends, some of whom are less technical than I am. They use Windows, Linux and Macs. Originally I just used javac to generate bunches of .class files, zipped it all up and had them unpack it all. It works, but they had to install the JRE (terrifying for some), write a script to run java or javaw followed by command line args, app name, more arguments (incomprehensible for some), mark the script executable... I got mocked, somewhat rightfully, for a geek solution. They wanted to download from a website, doubleclick and be up and running.
I thought creating a .jar file would be the solution. It didn't help. In Eclipse, the options seem to be "create a jar file", which lets me include the handful of resources (.png files mostly) the apps needs, but the result isn't runnable from a command line. Or, create an executable .jar file, which doesn't seem (at least from Eclipse) to have a way to include resources - and the resulting .jar file doesn't start when double-clicked, even when I set the execute bit, even though the default run environment points to the Java suit. Even with a .jar file, I'm stuck with having them script "java -jar App...", and that's pretty much a dealbreaker.
I'm missing something. The point of Java is platform independence. Is there a platform independent way to have them download a single file, double click it and have it off and running?
If you are trying to create a runnable jar file from your project in Eclipse, you have to select that option when exporting. You can do this by Export > Java > Runnable Jar File. If you only select the Jar File option, you won't be able to run it.
If you want to wrap your application as a .exe, you can use launch4j. Here's a thread that explains it a little more and has some other options.
I converted a java program (Number Guessing Game) to .jar but it did not run on double clicking so,ran it on cmd (it worked) now i converted it to .exe using launch4j but the application does not work either . Help!
Open your jar file with one zip application (ex winrar)
go to META-INF folder and open the file MAINIFEST.MF
put your main class there as follows
Main-Class: your-packaging.YourMainClass
save this file and try to create your exe file again
This will make your jar runnable, therefore when you create an exe file using Launch4J, your application will execute once you double click on that
If in any case your application did not run again, you have
dependency problem. for solving that you should also add Class-Path: within your MANIFEST.MF file!
I made a program in Java which uses plenty of pictures(every JButton has one).
I exported .jar file from my project and converted it to .exe using JSmooth. When I run .exe, everything works fine on my computer, but on other computers there are no pictures on the buttons. How should I provide those pictures with .exe, so everyone can use program, not only my computer?
I searched everywhere, but I can't find my answer, please help!
This is the example of loading images:
buttons[index].setIcon(new ImageIcon("cards\\"+(index+1)+".png"));
What is the reason that you want the jar file to an exe file?
If you mark the Java file as an executable, then you should be able to execute the jar on windows.
It is possible to package the pictures in your Jar. The preferred way is to adept the script where your IDE creates the jar. Which IDE (integrated development environment) do you use?
--- edited ---
The following code you need in your java code:
buttons[index].setIcon(new ImageIcon(getClass().getClassLoader().getResource((index+1)+".png")));
After creating the Jar file, you can open it with an archive program (like winzip or something like that), and you copy the images in the jar file (root).
If you want to do this program automatically, you need to generate an ant file. And adapt this ant file, so that it copies also the png on the fly, more info can be found here: https://ant.apache.org/manual/index.html
I've been working on a processing application using ControlP5 and Twitter4j. I want to have my project run from a single jar file from any operating system. Basically I want to package up my application. My application uses images. I've been browsing for more than an hour, but I cant find how to do this. Any suggestions?
using
processing 2
twitter4j3
Thanks in advance!
I dont know if you can directly do it from the Processing IDE however, if export your sketch to a Java applet then locate the .java the the sketch folder you can use this in conjunction with Eclipse to export to a jar file.
So, I know that this post is very old but if you are still looking for a solution, or to other people that see this thread, it's relatively simple.
Export the project
In the folder with the exported project (something like application.windows64), navigate to lib and find core.jar and project name.jar (you need to have file name extensions visible)
Rename the files to .zip files
Extract core.jar to whatever folder
Extract project name.jar into the same folder (make sure you don't do it into a subfolder)
Click yes if it asks if it wants you to replace a file (if it doesn't you extracted the files incorrectly)
Delete core.jar and project name.jar
If the project uses images, move them into the same folder as all the other files
Select all of the files in the folder, right click, hover over send to and select compressed (zipped) folder
Rename the .zip file to name of project.jar
This might be old, but i still find other posts about it on processing forums.
This is the best way to run processing project as a jar file.
When exporting application, you will always end up with a lib folder inside exported application(whether for Linux and Windows). For windows, open command prompt(or power shell), you can use right-click+shift and then click on open power shell here.
After that you can run the following command.
java -classpath lib\* DisplayDepthStream
Now DisplayDepthStream is the name of sketch file.
To explain the command, -classpath lib\* tells java to add everything under lib directory to the class path. And DisplayDepthStream is the name of my main class.
Hope this helps~!
Chears
Hi I have created a java application and created a jar file. Then I created a batch file eg-> startup.bat The contents of this file is java -jar MyApp.jar
Now if I double click the batch file then my java application works because both the jar file and batch file belong to same directory. Now I copied the batch file to desktop and run then My application did not run.
Also I want My batch file automatically set the class path.
How to create a batch file with all the above feature
Thanks
Sunil Kumar Sahoo
If the jar is an executable JAR (which it seems to be from your example), you should be able to just double-click the JAR file. If this does not work, you shoud associate the java executable as the program with which to open a file with the .jar extension. See Tools > Folder Options > File Types from an explorer window.
In order that a program be "distributable", it would normally be packaged (i.e. the JAR file and startup scripts) in some ZIP archive and then extracted to a folder on a user's PC. Your startup script should provide a relative path to the JAR file. For example if you have organized the contents of your ZIP into lib and bin folders:
MyProject
+--- lib (contains jars)
+--- bin (contains .bat script)
In this case, the startup.bat file should reference the Jar as:
%JAVA_HOME\bin\java -jar ..\lib\myapp.jar
This requires that any users:
Have a JRE installed on their system (unless you package that up as well)
Have java on their path or a JAVA_HOME environment variable set
The problem is that the batch file doesn't know where the jar is, it is looking relatively from its own path. You could copy the jar file to your desktop, too.
If just want an icon on your desktop, make a shortcut to the batch file rather than a copy.
Aslo if you application is quite complex (size more than 1+GByte) - you can distribute it with jre included.
Because it's a bit long to copy in here, I'd suggest that you have a look at what Squirrel SQL does. And you'll have a very nice cross-db tool as an extra bonus ;-)
They enable the tool to be started in two possible ways:
by starting the jar itself, classpath info will then be fetched from the manifest file (see here for the details, look up download extensions). In that case, after unzipping the hierarchy of files as explained by other posters, just make a shortcut on the desktop and you're all set
with a batch file. You'll see that the batchfile solution is quite complicated, especially the construction of the classpath.
So I'd go with the first solution.
I understand that you would like to distribute your application to multiple machines? A (very) simple solution would be to create a zip/tar/whatever archive that has all the needed jars (including MyApp.jar) and the startup script.
In the script you can use the -cp option to set the classpath to the jars:
java -cp needed.jar:needed2.jar -jar MyApp.jar
As said above, making a shortcut to the desktop is a better option than copying the script itself.