Creating a stand alone Java application - java

Is it possible to create a stand alone application in Java (using Swing) and package it into an exe file?
My Idea is, we should be able to double click it and run the application.

If you export a runnable .jar file you will be able to double click and run, but you'll still need the JVM in order to interpret the bytecode.

The best way to deploy a Swing based app. to a client's desktop is using Java Web Start.
JWS offers desktop integration - making a desktop shortcut and menu item, each using an icon if specified. The end use can double-click the desktop shortcut cut to launch the app. ( or single-click the menu item to do the same ;).
Best of all, JWS works for all platforms for which the J2SE is supplied. Windows, Ubuntu, Fedora, Solaris, Mac. OS..
For ensuring the user has the correct minimum JRE needed to run the app., use deployJava.js to write the link to the JNLP launch file.

If you export your project in a .jar file, you will be able to run it when you click on it.
I suppose that you know that you must have the virtual machine installed in the computer that runs the program.(The virtual machine is the thing that allows java to be operative system independent)
And also you must know that if you transform that .jar to an .exe file using some kind of gadget... Then java will not be java anymore, because will not be able to run it in non-windows operative systems.
Remember java slogan
'Write once run everywhere"
See this image here i will explain you how to create a .jar using the eclipse IDE:
1-Select your project in the package explorer
2-Select File>Export from the menu
3-Pick Runnable JAR file from the dialog and
4-Click next and follow the rest of the wizard

You can package your application to JAR file. Application in jar file runs on duoble click.
Here is tutorial. http://download.oracle.com/javase/tutorial/deployment/jar/

You can already do this with a normal .jar file if the user has configured the extension to be executed with the JRE. But you can always use something like Launch4J. Please Note this simply wraps the Jar in a EXE file. The file still needs your Dependencies (.jars) and the JRE enviroment.

Related

What is difference between executable and install able jars

I am developing one desktop application in javaFX. I am using in memory database hsqldb. I want to make this application to run on any windows machine by just double click or by installing.
I have gone through the launch4j library, using which I can make .exe file of my jar.
But if I create the .exe file, then I can open this application by just double clicking on it. anyone can copy and paste and open it.
I am confused with install word here.
What extra things will happens, if I want to make my application installable. Because I want to give an expiry date my application.
The answer to your question lies on the description of launch4j on their site.
The executable can be configured to search for a certain JRE version
or use a bundled one, and it's possible to set runtime options, like
the initial/max heap size
Not every machine you distribute the jar to may have a JRE. A bundled JRE will help the launcher run your jar if a JRE cannot be found on the target machine.
If you want to force updates on your jar, consider running a plugin mechanism or forcing the user to download a new version. It sounds to me like a web application might suffice instead ?

How do I run a java application like I would a typical program, using a shortcut?

I'm currently using an IDE for writing a java application and testing it. In the IDE, I can run the application and see how it works. However, how would I run the application using a shortcut, or a jar file?
For example, in order to run my WAMP server, I run the wamp.exe file in the WAMP directory. So, I'm running a single file which launches the entire program. How do I achieve this sort of thing with a java application? I've heard about using a jar file, but I'm unsure about whether that would be the proper way to do this or not.
It depends on the IDE you are using. With eclipse for example, you open up the file tab, select export, open java in the tree, and select runnable jar file. Then fill the interface out and your good to go.
If you are using Eclipse, then you can export your application as a single jar file and run it directly by double clicking
In the Package Explorer view:
Right click on your project
Go to "Export"
Click on "Export as Runnable Jar"
And you are done
And if you are using Netbeans, then follow these steps:
Right click on your project
Click on "Clean and Build"
Now got the directory where your netbeans projects are created( usually it should be "C:\Users\your_user_name\Documents\NetBeansProjects"
Open the directory of your project (directory with the name of your project name)
Open "dist" folder and you'll find the jar file of your application/project there.
Java Web Start is the easiest way to add shortcuts for a desktop app.
Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
See also
This answer - the 2 icons on the right "JotPad" & "Star Zoom Animation" are icons installed by JWS.
You can also, just for fun, create a launcher in C++ that launches your executable(the way Limewire did it). A simple console mode C program is given below.
#include <stdlib.h>
int main(int argc, char *argv[]) {
system("java YourProgramClassFileNameHere");
return 0;
}
An advanced methodology would require CreateProcess() in win32API or in JNI for your platform.
You can convert it to an executable Jar file(See Abu's answer)
You can also, create a bat file which can run your program: (Windows only)
#echo off
start java YourProgramClassFileNameHere
Or a shell script(BASH)
Also, see here run a executable jar from c++ code

Convert Java Project to .Exe

I've created a game project in NetBeans 6.9, and I want to run the project on another computer. The problem is if NetBeans is not installed on the other computer then surely I cannot run the project.
Therefore I have to convert my project into a .exe that can be run on other computers without having to install NetBeans.
Is there a free application that can convert .java to .exe?
Please help me to convert my project into a .exe file. Thanks.
Check out these official netbeans article for Packaging and Deploying Desktop Java Applications and Developing General Java Applications.
From the article
Running the Application Inside of the IDE
When developing applications in the IDE, typically you will need to test and refine them before distributing them. You can easily test an application that you are working on by running the application from the IDE.
To run the AnotherGrep project in the IDE, right-clicking the project's node (AnotherGrep) in the Projects window and choose Run Project.
The xGrep window should open. You can click the Browse button to choose a file in which to search for a text pattern. In the Search Pattern field, type text or a regular expression pattern that you would like to match, and click Search. The results of each match will appear in the xGrep window's Output area.
Information on regular expressions that you can use in this application are available here and in many other places on the World Wide Web.
Running the Application Outside of the IDE
Once you have finished developing the application and before you distribute it, you will probably want to make sure that the application also works outside of the IDE.
You can run the application outside of the IDE by following these steps:
In your system's file manager (for example, in the My Computer window on Windows XP systems), navigate to PROJECT_HOME/dist and double-click the AnotherGrep.jar file.
You will know that the application has started successfully when the xGrep window opens.
If the xGrep window does not open, your system probably does not have a file association between JAR files and the Java Runtime Environment. See Troubleshooting JAR File Associations.
Distributing the Application to Other Users
Now that you have verified that the application works outside of the IDE, you are ready to distribute it.
You can distribute the application by following these steps:
1: Create a zip file that contains the application JAR file (AnotherGrep.jar) and the accompanying lib folder that contains swing-layout-1.0.jar.
2: Send the file to the people who will use the application. Instruct them to unpack the zip file, making sure that the AnotherGrep.jar file and the lib folder are in the same folder.
The users of your application should be able to run it by double-clicking the JAR file. If this does not work for them, show them the information in the Troubleshooting JAR File Associations section.
Also some third party tools like Launch4j may do the trick. For more information see this article on java-to-exe
See Launch4j. I dislike starting java apps with a batch file. This wraps anything from the root jar all the way up to a complete Java environment in an exe. You get your own icon in the system tray rather than the generic coffee cup. I've used it successfully on a project that has about 300,000 downloads, and it's never been the source of a reported bug. NB It does take some careful reading to pick the right options for your project. But you can set it up with the Ant build script in Netbeans to make the .exe automatically. Very nice and clean. My project includes native libraries. They work fine as well.
I think the NSIS will help you . Most of the applications using NSIS. Because it is open source.
Also there is a Eclipse plugin for NSIS to make the process easy.
http://hmne.sourceforge.net/

Exporting a program in Eclipse that works for people not familiar with Java programming

I made a little minesweeper game and I want to send it to a friend so he can test it out. The problem(probably) is that he isn't able to run it because he doesn't have Java for programmers(JDK) installed on his computer. How is it possible to export a program that will work on other computers without having to download any other files**(other than JRE)**?
EDIT: I did read about converting the JAR to EXE but I couldn't find anything that would do it.
EDIT2: Download here the JAR file(it's only supposed to open a blank window). I tested it on two computers with JDK installed and it worked, whilst on two others without JDK(one with the newest JRE) it couldn't start. This is the error:
.
There is no way to "not have to download any other files" - your friend must minimally have some Java Runtime Environment (or just "Java") installed in order to run Java programs.
If your friend has Java installed, you can package your application as a fat JAR so that he only needs your JAR to run your application (depending on the application - but I think yours should be fine).
There are tools available, google "java windows executable" and you will find e.g.
Convert Java to EXE
http://jsmooth.sourceforge.net/
Or already on SO
How can I create a Windows .exe (standalone executable) using Java/Eclipse?
Java Web Start is ideal for this, as it can enable the user to install required components on supported platforms. There's a simple example here.
Not possible, a JRE (Java Runtime Environment) is the least that must be present.
If that is you can just export your program as jar specifying the main class in its manifest. Your friend should if a JRE is installed be able to run the jar file directly.
You could send your friend the compiled binary of your game. In that scenario, your friend will only need to have the Java Runtime Environment installed in order to play your game.
Make executable JAR from it, your friend will still need JRE.

How to create a .exe file in netbeans?

I've created a project in netbeans and I want it to be runnable in another computer without having the netbeans installed (just like a .exe in visual basic).
I pressed F11 and I got a lib folder which has a .jar file on it. But then I don't know how to work it out, which one do I have to double click?
Can anyone please guide me?
If you created a java project, then the "other" computer should have the java runtime installed, in order for the jar to be executed there (java -jar your.jar) otherwise if you really want an .exe use one of the many jar2exe converters found on the almighty internet, such as http://www.ucware.com/jexec/index.htm
To run jar file on other computer you should have at least jdk. Their is no need to install NetBeans but you have to first set database connectivity to pc and your database. After connectivity just double click on jar file your project will run.
To know how to create Jar file in NetBeans check this link.
What type of project is this Desktop application OR Web based application ? If you are using java then for Desktop application you need to create a *.JAR and for Web based : *.WAR.
There are simple step to create jar/ war. please follow any tutorial.

Categories