Executable .jar - works for some users, but not others - java

I recently released an application in the form of a .jar file (built using Eclipse's "Export Runnable Jar File", using Java JRE 6). Most users are able to double click the file and have it run properly, but a few have reported that double clicking the file causes javaw to start, and immediately exit (with no error message).
I have talked with a few users, and walked them through the process of running the .jar from the command line. The users with the issue seem to be getting "Main class not found" errors, even though the .jar has a META-INF folder with a properly formatted MANIFEST.MF file inside.
Is there anything I can do to insure the program will run properly? Is the issue more likely in my program, or in their Java environment?
Thank you.

JAR is non-executable file format and its extension might be not associated with Java. Its better use open source tools like Launch4j or JSmooth to wrap your JAR as an executable file. This way makes your application more user friendly.

Related

How to properly make jar archive to run Java program on different systems?

I have this, perhaps, easy problem, but I don't know how to handle this.
I have my Java program and it works pretty well when I call it via terminal (Java command).
The program uses 4 text files from the hard disk which can't be added as resources to the project.
How to do this right so I could build jar file only with main class and files from hard disk (first one is a config file and it has paths to other files so the program knows where they are)?
I'm using IntelliJ IDEA 14.1.4 on Arch Linux.
I did it based on this blog, but it's not working without txt files in src folder.
Also "jar cvf" command builds jar file, but it's not working outside my computer (for example on windows or OSX).
Can anyone help me?
I prefer step by step instruction so I would understand what is going on in here.
I recommend to build your application with Maven and create a Maven Assembly which contains your JAR file as well as the config.txt file.

Java - Executable Jars

I wrote a Java GUI program in Netbeans IDE 8.0.1 called SampleChat and used the 'clean and build' function to create a jar file.
I went to the 'dist' directory that Netbeans created and double-clicked the jar file it produced.
A cmd window opened with the following line:
"Error: could not find or load main class.
However, when I opened cmd, changed to the same 'dist' directory and typed the command:
java -jar "SampleChat.jar"
the program ran just fine.
Can I not use Netbeans to create jar files that execute on double-click?
I did not use any pre-existing jar files to complete the program, hence, there was no 'lib' directory or anything like that.
I intend to share programs from a USB stick so it is vital that the only requirement is a JVM, mouse and maybe some fingers to double-click it.
An awkward solution I came up with is to write a batch file that runs the program, but it requires the jar file to not be moved around - screw that.
So how do I make my programs double-click executable?
I guess you are missing to create a manifest file. Therefore it's unknown what your mainclass is. In your java command executed from a terminal you defined the mainclass to execute.
From the tasks you mentioned I guess you are using gradle to build your jar?
Here http://www.gradle.org/docs/current/userguide/java_plugin.html in chapter 23.14.1
an example of an manifest is given.
If you add attributes 'Main-Class': 'com.project.MainClass' it should work.
BR

How do I make a final executable file for my Java program?

I created a tic-tac-toe game in Java. It runs fine on Eclipse.
How do I compile this file (which is currently a .java file) to the standard file format of Java applications, so it can be run from the desktop like a normal program?
What is the standard file type for the final executable Java application? What should be the file type if I want people to easily and without any computer knowledge run my program on their computers?
with eclipse right click on your project. then export it as a runnable .jar file.
Project Right Click > Export > Runnable .jar File.
First choose your project under "Launch configuration", then choose your destination.
After that click finish. Your program should be in your destination folder. Double click to start (just like an .exe file)
For example: If you export it to your desktop, and you name it "TicTacToe", the file on your desktop is "TicTacToe.jar" - ".jar" is your executable file
Done
You have to compile your java class first
javac TicTac.java
and then execute it
java TicTac
Note: that here you provide the name of the class with the main method!
As the other answers indicated, you can create an executable jar using eclipse (or a number of other tools). What these tools are doing under the hood is defining the Main-Class: attribute in the jar's manifest.
In Windows, your users can double click on an executable .jar to launch it, as long as the file associations are configured correctly. However this may not be obvious to windows users who are trained to expect some sort of .exe extension.
To solve this, you could use launch4j to wrap your executable jar in a windows executable. Note: this doesn't change your java application into a native application (it still requires the JVM, etc), it simply makes it launch more like a native application.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS works on Windows, OS X & *nix.
Note that JWS is more effort for us to deploy (it involves not only Jarring and signing the code, but creating a JNLP launch file and a page on the net or network to check that Java is installed & serve the files to the user), but is super easy for the end user.
If there is a JWS deployment, the Jar does not have to be an 'executable Jar' as described in the other answers.
The command should be javac yourFile.java from you command prompt and then after compilation, class file is created. You can run it using java MailClassName
You can find a good tutorial on using javac and java commands here.

Exporting java project from netbeans to executable jar

Used eclipse in the past fro java coding and didn't have many issues but decided to give netbeans a blast
I'm trying to create a jar file with all dependencies as one jar and yes am familiar with the java-web-start-option and also the jar actually exists in my dist folder once built.
Problem 1
All's good and well, I can launch the jar but seems not without its lib folder which contains: AbsoluteLayout.jar + beanbindings.jars. Something I will need to figure out as I go along.
I call a few batch scripts to complete differenet jobs for me in the java program e.g. one finds memory amounts and displays in a JTextArea. When I use the program within the netbeans ide all works fine.
Problem 2
When I launch the jar file thats in the dist folder it launches just fine but cannot find the batch/bash scripts at all. Below is the path I use within the program which as I mentioned works fine in the IDE and just wondering why it cant find the same path in the jar.
I assumed when I created and built like in eclipe it would make all these commands work in the existing jar in my dist folder (bin in eclipse ofc)?
String[] filepath = {"cmd.exe", "/C", "..\\Enterprise\\src\\enterprise\\batch\\memory.bat"}
Any suggestions, thanks in advance!
Just try to change your path. Just make a flag if it's in your ide then select this path, if not then use another path.
Try this link to get the application path in java.
Get the application's path

How to create an executable (a file that starts the program on double-click like an .exe) in JAVA with Eclipse?

I've created a program in java and now I want to create an executable from it.
I'm new to java, I don't know if it should be a .exe.
I'we exported my project to a .jar file, but when I double-click it it opens "open with" window.
I want to export my project to a file that runs my program on double-click.
Is there any solution?
Export --> Java --> Runnable Jar file --> Specify the class with static main method to run.
Double click on the Jar file to run..
Thanks...
Java compiliation creates byte code for the JVM, so a native, binary executable is not created during compiliation (like C or C++ programs). This is a feature of Java.
To deploy an application to multiple systems they must have the JRE. These .jar files can be launched from the command line (see this: http://download.oracle.com/javase/tutorial/deployment/jar/run.html)
Some vendors get around this with batch files that launch the JRE to run their application's JAR (and then put these in the start menu, desktop, etc with a fancy icon).
If you want people to install your app (especially from a web page or over a network) you probably want a Java Web Start package (see this for crating one in Eclipse: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fjava_web_start.htm)
If you just want it to be runnable on your computer, you can use the open with dialog to open it with javaw.exe in JDK_DIRECTORY\bin. Alternatively, if you really wanted to make it an EXE, you could look at some of the answers here.
Either do as in the link mentioned by #dacwe or I would suggest to depending on operating system set a permanent connection between java and jars, then it will always happen.
On Windows you do it by right clicking on any jar then open with and find your javaw.exe in bin folder of your jre installation.
I think you are looking for a simpler approach than Java Web Start.
I assume that you are a Windows User, since you want a .exe file.
So once you have the exported MyProgram.jar file, you only need to create a .bat file
that contains a sole line:
java -jar MyProgram.jar
and place this execute.bat file in the same folder as your MyProgram.jar
This approach works for Linux too, only you need to place it inside a similar file and execute the same command.
Read here http://javabeanz.wordpress.com/2009/01/29/running-an-executable-jar-from-command-line/ for more explanations.

Categories

Resources