Run Java applications By double click - java

why i can`t run my java compiled applications with double click?
my applicatins just run in cmd (java -jar: my app.jar)
plz help me

You can make a batch file to run your command. This way it will work without the need to make associations to .jar files. If it is a windows app then start it with javaw.exe.

You need to associate the .jar extension with javaw.exe, then no console window will be shown, when you double click the jar file
This is usually done by the JDK/JRE installer, so either you didn't install the JDK properly, or you manually changed that associaten.

I think all the answer here are valid. But if you want a true executable file in Windows then you need to create a launcher. In windows, jar files are not executable. But exe files are. There are many tools out there than wrap all your java code around some native library. I recommend http://launch4j.sourceforge.net/ I think this is what you are looking for. You can easily create executable with icons and many more features.

You can create a Windows shortcut to your .jar file.
The following line could be the target of the Windows shortcut.
%windir%\system32\javaw.exe -Xms1m -Xmx1m -jar "C:\Program Files\Jar Directory\file.jar"
This has the advantage of allowing you to specify the javaw parameters that you want, as well as the Windows parameters (normal window, maximized, start in directory) that you want.

Just assign .jar files to be executed by javaw.exe. You can do that using the Open with dialog on a .jar file.
BTW, doesn't the Java installer do that for you?

Related

Windows, run JAR with double click

I'm experimenting with Java for the first time.
I'm using Intellij IDEA and creating a simple app.
In the IDE it's working fine, then I create a JAR artifact and run it like this:
java -jar myappname.jar with no problem.
Now I would like to start the same JAR with double-clicking it from explorer but nothing happens, why?
Please note that if I double click another JAR (sikulixsetup-1.1.3.jar) it starts correctly and show the gui, so the problem is not type association in windows.
My test app does not have a gui but I know if it runs correctly because it's automating windows using Sikulixapi library, so I see if it's doing something or not.
thanks!
Ok, I solved my issue.
Usually the JAR runs without any problem by simply double clicking it in windows,
in my case it was not running becase the .jar files was associated to the 32bit version of javaw.exe while the code in the JAR was expecting the 64bit environment.
Changing the .jar type association in windows from 32bit to 64bit version of javaw.exe solved the issue
Its because jar is not executable binary but plain zip archive. OS cannot execute that. That is why you must use java executable and pass archive as argument to run your application.
If you want your app to be "clickable" you must use some wrapper solution like http://launch4j.sourceforge.net/
Change the default program to use while opening the file from one Java to the other (32 to 64 bit or vice-versa).

Executable jar doesn't start normally

I created an executable jar file with eclipse indigo, but when i double click on it nothing happens. But when i write java -jar c:/dir/filename.jar to cmd, it works. Other jars runs well. I'm using jdk 1.7.0_02 and eclipse indigo. How could i start it normally?
You can run a jar by double clicking it, you just have to make sure that Java is associated with .jar files. The easiest way to do this is by reinstalling the JRE (which generally does it for you).
Otherwise you will need to modify some of your Windows properties (I'm not sure what version of Windows you are running) to point .jar files to the instance of javaw.exe.
Here's a link to a Windows 7 page on how to do it.
right click on .jar file and go to properties, then set "open with" program to "Java SE Binary".
You can do this by associating the .jar extension with the command to run it via javaw.exe.
"C:\Program Files\Java\{java version}\bin\javaw.exe" -jar "%1" %*

Is it possible to convert a jar to exe using Ant build in Linux?

I have created an project and need to distribute it over Windows. I need to create an exe for it I already know that there is a lot of tools like:
JSmooth
Launch4J
Executor
Advanced Installer etc.
The installer windows are done in Java itself. Means like the selecting locations, licensing etc. the only thing I need is to create an exe that should open this jar. Is that possible in Linux?
For a Java app. with a GUI, Java Web Start is the best option. It is supplied and maintained by the maker of the JRE, and therefore works on Windows, *nix and Mac.
I do understand the need for an .exe on Windows and I've used JSmooth before.
I would just make a shell script which launches the program. I think a shell script is fine for Linux: icons aren't built into the executable and you can't discover the location of a usable JVM automatically.

Creating a stand alone Java application

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.

Executable JAR on Ubuntu (NetBeans)

I'm writing a simple Swing application in NetBeans and doing so on an Ubuntu machine for the first time.
As many of you know, NetBeans automatically creates executable JARs for projects that are "set as main".
On Windows, you can double-click an executable JAR and it automatically invokes the JRE and runs the app. In Ubuntu, double-clicking the .jar file causes the file to be opened in the archive manager instead. In order to run my JAR, I either have to right-click it and select "Open with OpenJDK Java 6 Runtime" or launch it from the command line.
From the command line I get no problems whatsoever. However, when I try launching it from the right-click menu, I get an error that reads:
The file MySwingApp.jar is not marked as executable...
So I have 2 questions:
What do I have to do to set it as executable? Is this something I can do inside NB or do I have to use the shell? If I have to set permissions via the shell, doesn't that conflict with NB's policy of auto-generating **executable** JARS? And what command would I use to flip the executable bit anyhow?!?!
Is this just a Linux hiccup? I want to send this JAR to friend who run Windows and I'd like for them to be able to just double-click it and have the program launch
Thanks for any helpful suggestions!
You will need to manually tweak your build process to get the jar file marked as executable in Netbeans. Go to your project root and open build.xml. The header has instructions on adding to the build process. There is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine on your friend's Windows machine, as long as he has a JRE installed.
Here is a thread about running jars using double click in Linux.
You can Java like a native binary on Ubuntu (and other linuxes), it's a feature of the kernel. You need to install the binfmt-support package to give the kernel the hooks to run java in this way.
In Ubuntu open up a terminal and run:
sudo apt-get install binfmt-support
Then make your JAR file executable
chmod a+x yourjar.jar
Then you can run your JAR like any other binary by typing
yourjar.jar
Jar-files aren't first class executables, and they don't become magically executables by changing their executable flag.
If you execute a jar, you run the command
java -jar YOURJAR.jar ...
It's the same, as if you double click a png file, and expect it to run in a painting program
gimp YOUR.png
You don't need to make your png an executable one, and it will not solve a problem.
Instead, you have to tell your desktop environment, what to do when double clicking a jar or png-File, and you have to do it on Linux the same way you do it in Windows - maybe the installer on Windows does it for you, because there is normally just on Desktop Environment (Windows) on the OS (Windows), but Linux has Gnome, KDE, XFCE, LXDE, fluxbox and millions more.
And it isn't so sure what you want to do with it. Since jar-files are a special form of packed zipfiles, usually containing a Manifest and the classes, the Archivmanager isn't a false solution, and it is saver to show the content of the archive, than executing it.
Copying the file to windows has no effect. Windows not even has an executable flag, but you shouldn't fiddle with it though. You change your desktop settings, and those can't be moved to windows, and you will not want to.
And if you have the correct settings in your DE, you don't need to tell Netbeans or any other IDE repeatedly, what to do with jar-files.
I gone through Internet and I came across one article with complete steps to run jar file
http://mlartist.blogspot.in/2012/07/deployment-netbeans-project-in-linux.html
Jar files are basically a zip file, to create an executable, you have several different methods. The Best (in my opinion) is to use ant to create it. Or you can simply echo "Main-Class: YOUR.MAIN.CLASS" >> Manifest and then create your jar by jar -cmf Manifest JARFILENAME.jar INPUTFILES then, to make it executable under linux, right click on it and click on properties. Then click on permission tab and check execute. or you can be a terminal bamf and cd to the jar directory and chmod +x JARFILE.jar
HAPPY NIXING!!

Categories