Double click won't start executable jar - java

I ran into a strange issue.When double click an executable jar it won't open
however if I do the following it starts without a problem:
java -jar working_neon.jar
This jar is a swing gui application.The jar file creation is done by eclipse
Here is the manifest file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ miglayout15-swing.jar Message.jar org.apache.commo
ns.io.jar
Class-Path: .
Rsrc-Main-Class: gui.FileCopyManager
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Any ideas?

If you are using eclipse: Go to File->Export, under Java folder select 'Runnable JAR file', under Launch configuration select the class where your main method is. Select the export destination, then select Library handling to 'Package required libraries into generated JAR', and click on finish. This works for my swing gui app. I hope it helps

Make sure that you don't use a higher Java-version in Eclipse Project-settings / Run-Configuration than the JRE used to run the jar.
In Eclipse right-click you project -> Properties -> Java-Build-Path -> Libraries.
There you will see the JRE-Version that will be required to run the jar. (Also check the JRE-Version set in Run-Configuration)
Open commandline and type
java -version
Make sure the version displayed there is at least as high, as the one you found in Build-Path and Run-Configuration!
If the version displayed is not as high as the version in build-path either decrease the JRE-version set in Eclipse Build-Path/Run-Configuration or - if not possible - change your PATH-variable to use a higher versioned JRE.

Finally managed to fix my problem by selecting Extract required libraries into generated jar when creating a jar file from eclipse

Related

Showing error " JavaFX runtime components are missing, and are required to run this application" while running jar file in command prompt

I created a project in IntelliJ and built a jar file from it (the main class is specified). But when I tried to run the jar file using cmd I am getting this error: JavaFX runtime components are missing, and are required to run this application(in command prompt). How can I fix this issue? (I am new to this. Please try to explain as easy as possible.)
cmd command: java -jar filename.jar
In the end, what I want is to run my JavaFX application just by clicking a single icon. How can I do that??? Are there any other ways to run my application like any other application run, just by clicking one icon? I don't want to open IntelliJ every time to run my application.
I used:
OS: Windows 10 | IntelliJ IDEA 2020.2.3 | jdk 14.0.2 | jre 1.8.0_251 | javaFX 15
(By the way, I installed JavaFX 15 in another drive. Not in the same hard drive which contains OS)
you can try this:
right click on your project then select export after that select export as runnable jar file don't forget to select second choice you have to export it with used lib, this should be able to run your jar using cmd
and try to load all modules, not just javafx.controls
--module-path "put_here_the_path" --add-modules=ALL-MODULE-PATH
Or
You can do this step it can help
File >> Project Structure >> Modules >> Dependency >> + (on left-side of window)
click the "+" sign to designate the directory where you have unpacked JavaFX's "lib" folder.
then:
Run >> Edit Configurations
to fix this error try to load all modules
--module-path "put_here_the_path" --add-modules=javafx.controls,javafx.fxml
What you want to achieve can be done via the jpackage tool introduced in JDK 14.
Have a look here: https://github.com/dlemmermann/JPackageScriptFX
Since you are using IntelliJ-IDEA, then you follow these instructions.
Go to Run → Edit Configurations
Go to VM Options and add these arguments:
--module-path "C:\Fx\javafx-sdk-11.0.2\lib"
--add-modules javafx.controls,javafx.fxml,javafx.base,javafx.web
--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
Just know that, for mine, I created the folder and stored the JAR files in that directory. For that part, you modify it and the rest is history. You just need to change the directory of the path to where you store your JavaFX JAR Files.
I have added -Djava.library.path=C:/go-out-of-my-way-eclipse to the runtime arguments. I don't remember where I had found this advice.

How can I Export my Java Project in Netbeans in Executable(.exe)?

I have completed my project but unable to export in executable form. I'm using Netbeans 12.
Java applications aren't built as exe files but as jar files. The component that makes them executable is the Main-class attribute defined in the META-INF file of the jar.
In NetBeans to turn your program into an executable jar file
1)Right Click on your project->Properties->Select Run Tab on the left corner of your screen. You will see an text box saying main class, select the drop down arrow to browse through all main classes available in your project (Yes NetBeans can have multiple main classes but will run only one)
2)Optional Select the deployment tab and select compress jar to save space
3)Right Click on project->Clean and build
Then go to your projects folder on your file explorer you will see an dist(distribution) folder and there you will see your built jar file named (Project Name).jar simply double click it and the java jre will execute it
Some people have a problem running the jar file with double clicking in that case either from cmd or from an bat file type this script
set path=<path to your java.exe in your JDK/JRE bin folder>
cd (Path to where your jar file is located)
java -jar <Your Jar file>.jar
Thanks for everyone who wanted to help me.
Easiest Solution:
Start an Ant based standard project
Enable native packaging inside Properties->Build->Deployment
Install Inno setup tool for Exe, Wix Toolset for Msi
add bin paths of above tools as system environment variables
right click on project and select package as->Exe or MSI
Note:
Netbeans 8.2 is recommended (some features are deprecated in latest version)
Screenshot
You can use Files>Export>Browse to Export in netbeans.

java - Sharing an executable .jar file

I wrote a program in NetBeans, and now want to share it with my coworker. However, when he tries running it on his computer, he gets an error message:
"Could not find the main class: excelcomparator.ExcelComparator. Program will exit."
Here's the confusing part: I wrote this on my laptop which has NetBeans, and to make sure that it worked, copied the dist folder onto a flash drive, and ran it on my computer. It worked fine. When I emailed it to my coworker, he got that error.
Based on what I've seen, some solutions are to run the .jar from the command line. While that might work, I need the file to be double-clickable.
I sent my coworker the file via email in a zipped folder, is it possible that unzipping the entire folder also messed up the .jar file (don't see why it should, but included anything that might help)?
This is the MANIFEST.mf that's within the .jar file. There is a carriage return at the end of the file, it just doesn't copy well into this text box:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Class-Path: lib/poi-3.12-20150511.jar lib/poi-examples-3.12-20150511.j
ar lib/poi-excelant-3.12-20150511.jar lib/poi-ooxml-3.12-20150511.jar
lib/poi-ooxml-schemas-3.12-20150511.jar lib/poi-scratchpad-3.12-2015
0511.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: excelcomparator.ExcelComparator
I sent the dist folder, which includes the lib folder which contains all the additional .jars.
If there's any other relevant information I need to include, let me know. Thanks!
If you want the JAR to be double-clickable then you should bundle all the dependencies into a single JAR file.
You achieve this using the maven assembly plugin: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
If you don't know how to use Maven, Eclipse has a nice wizard. I'm not sure how it works on NetBeans but the same question has been asked many times, e.g. here Netbeans Export to Jar, include all library files
Just to finish this off, I'll write what ended up working for me:
As per Franz Becker's suggestion based on this question, I bundled the entire program into a single .jar file.
I was still getting the same error on my coworkers computer, so based on other suggestions I saw, I guessed that the problem was based on different versions of Java installed on our computers. What I did was recompile the program to an earlier version of Java, which works with any version from then and onward (other people suggested reinstalling Java on the users computer. That's a bit too unrealistic in most scenarios).
To change the compliance level (in Eclipse): right click on the project in Package Explorer, select properties. Choose Java Compiler in the options on the left. Uncheck 'Use compliance from execution environment [default target JavaSE] on the 'Java Build Path'', and change 'Compiler compliance level' to your level of choice (I picked the lowest option available, 1.3, as I assumed anything higher than that wouldn't be an issue).
I then exported the file (File -> Properties -> Java -> Runnable JAR File), and had a working, clickable .jar.
Thanks to everyone for their help!

JFreeChart Java JAR not running on a different machine

I have created an application using the JFreeChart library for use on another machine.
Previously I have developed applications with JFreeChart (using the same libraries) which has worked fine on other machines. The only difference is this machine is running Vista.
Please see below for the run-time exception I am getting:
The class that cannot be found, however, is located in the highlighted jar in the below image showing my imported libraries for the JAR. I have also established that this JAR is included in the manifest for the application. See below image:
So I very much need this to work and have no idea where to look next - or what is causing this problem!
Development machine Java version:
1.7.0_45
Target machine Java version:
1.7.0_45
Thanks in advance.
Check the Class-Path attribute in your JAR's manifest, which should contain entries like this:
Class-Path: lib/jfreechart-1.0.17.jar lib/jcommon-1.0.21.jar …
Also, examine dist/README.TXT in your NetBeans project folder, which should say something like this regarding libraries required by your project:
To run the project from the command line, go to the dist folder and
type the following:
java -jar "CISOnlineMonitor.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
This has nothing to do with os i belive.You dont have all the necessery libs within your jar.Try to open a jar and see if you have them in.Fact that you are able to run it on your maschine only proves that.Make executable jar with eclipse or whathever you use.And when it ask you for libs check -Extract required libraries into generated Jar.
if you dont know how to get to that point
File>Export>Java>Runnable Jar File> Runnable JAR File Specification.
Also right click on your project and check Your build path.
RightClick project>Properties>Java Build Path>Libraries
Make sure you have everything correct
EDIT-
As i see you use NetBeans im not sure exactly how to find all this there.Bud it will be very similiar.

How to open/run .jar file (double-click not working)?

I can't open or run my .jar file.
I just installed java, but I tried to open the .jar with other programs first, so the double-click defaults to something else and I can't change it back.
java -jar myfile.jar`
Above command returns:
'java' is not recognized as an internal or external command, operable program or batch file.
Is there a way I can still open/run this?
e: OS is Windows 8.
Also, I downloaded the .jar file; didn't create it myself (if that's relevant)
Not sure if it contains an executable (but I think it does).
you can use the command prompt:
javaw.exe -jar yourfile.jar
Hope it works for you.
There are two different types of Java to download: The JDK, which is used to write Java programs, and the RE (runtime environment), which is used to actually run Java programs. Are you sure that you installed the RE instead of the SDK?
Use cmd prompt and type
java -jar exapmple.jar
To run your jar file.
for more information refer to this link it describes how to properly open the jar file.
https://superuser.com/questions/745112/how-do-i-run-a-jar-file-without-installing-java
You may have several JDKs installed in your PC. Some older JDK installers also copy some java files such as java.exe, javaw.exe into C:\Windows\System32 folder.
I had a similar issue, and searched the internet for a solution and none of the suggestions didn’t open by double clicking the .jar file.
In my case the reason is I have multiple JDK & JRE versions installed on my computer. Since I am a software developer working with several different versions for different clients I need to use multiple JDKs in my PC (Windows 10 Pro). So I do not want to change the system variables (i.e. JAVA_HOME, JRE_HOME or PATH), instead I use command prompt to run java in user process whenever I wanted to use a different version.
When installing JDK it registers the .jar file association with latest version we installed in the PC. If you right click on the .jar icon and select properties, it will show that file opens with “Java(TM) Platform SE Binary”. If we look at the registry key: HKEY_CLASSES_ROOT\jarfile\shell\open\command, it will point to latest JDK version.
It is not a good idea (sometimes annoying) to change the registry key every time I want to run an app build from a different version.
So in my situation it is impossible to just double click the .jar file to execute it. But instead I found a work around solution myself.
Scenario:
Multiple JDKs (1.7, 1.8, 9.0, 10.0, 11.0, and 12.0)are installed in the PC, so the latest installed was 12.0.
Problem
Want to double click an executable .jar developed using JDK 1.8 and didn’t work
This is my work around solution:
Create a shortcut for the .jar file that you want to open.
Right click the shortcut icon and select properties -> Shortcut tab
Change the text in the target (for example "D:\Dev\JavaApp1.8.jar")
To
"C:\Program Files\Java\jdk1.8.0\bin\javaw.exe" -jar
"D:\Dev\JavaApp1.8.jar"
Then click ok Double click the shortcut.
It should now open the app.
I was having this same issue for both Windows 8 and Windows Server 2012 configurations.
I had installed the latest version of JDK Java 7 and had set my **JAVA_HOME**system env variable to the jre folder: *C:\Program Files (x86)\Java\jre7*
I also added the bin folder to my **Path** system env variable: *%JAVA_HOME%\bin*
But I was still having problems with double clicking the executable jar files. I found another system env variable OPENDS_JAVA_ARGS that can be used to set the optional properties for javaw.exe. So I added this variable and set it to: -jar
Now I am able to run the executable jar files when double clicking them.
In cmd you can use the following:
c:\your directory\your folder\build>java -jar yourFile.jar
However, you need to create you .jar file on your project if you use Netbeans. How just go to Run ->Clean and Build Project(your project name)
Also make sure you project properties Build->Packing has a yourFile.jar
and check Build JAR after Compiling
check Copy Depentent Libraries
Warning: Make sure your Environmental variables for Java are properly set.
Old way to compile and run a Java File from the command prompt (cmd)
Compiling: c:\>javac Myclass.java
Running: c:\>java com.myPackage.Myclass
I hope this info help.
Go to your java directory,
Copy this path
C:\Program Files\Java\jdk1.8.0_40\bin
Right click on my computer , click properties, then go to "Advanced system settings"
click , Environment variables.
go to "System variables" table, find an entry named "path".
Double click it and go to the end, put a semicolon and paste your path, apply and ok.
It should run now.
first of all, we have to make sure that you have downloaded and installed the JDK.
In order to download it click on the following link
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
(Do not forget to check "Accept License Agreement", before you choose the version you want to download)
For Windows OS 32-Bit (x86) choose "jdk-8u77-windows-i586.exe"
For Windows OS 64-Bit (x64) choose "jdk-8u77-windows-x64.exe"
Install the file that is going to be downloaded. During the installation, pay attention, because you have to keep the installation path.
When you have done so, the last thing to do, is to define two "Environment Variables".
The first "Environmental Variable" name should be:
JAVA_HOME
and its value should be the installation path
(for example: C:\Program Files\Java\jdk1.8.0_77)
The second "Environmental Variable" name should be:
JRE_HOME and its value should be the installation path
(for example C:\Program Files\Java\jre8)
As soon as you have defined the Environment Variables, you can go to command prompt (cdm) and run from every path your preferred "java.exe" commands. Your command line can now recognize your "java.exe" commands.
:)
P.S.: In order to define "Environment Variable", make a right click on "This PC" and select "properties" from the menu. Then the "System" window will appear and you have to click on "Advanced system settings". As a consequence "System properties" window shows. Select the "Advanced" tab and click on "Environment Variables" button. You can now define the aforementioned variables and you're done
You must create a manifest file and specify your class that has the main method. you can build your jar file with manifest file as a parameter.
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Cakes
Build-Jdk: 1.6.0_04
Main-Class: com.foo.App
An easy way to execute .jar files is to create a batch file.
Let's say you placed your jar file on your Desktop;
#echo OFF
java -jar C:\Users\YourName\Desktop\myjar.jar
Copy this code to a .txt file, modify "YourName" and save as "myjar.bat". Then whenever you double click, the jar file will be executed.
Hope this helps.
Short trick: after I only REMOVED SPACES from names of the folders, where the .jar file was, double-clicked worked and the file executed.
In Netbeans please delete current you create the jar file and on the project explore of Netbeans please clean and build 2 or 3 times and right the project folder in project explore and build the jar file.
I had this problem a while back and the solution was really easy.
Just uninstall the current version of Java, download an older one, then uninstall the older and install the latest again.
For example: Java 8 Update 73 current install Java 7 Update 95.
How it works: Java's registry keys were messed up, and when you install the older version they get fixed.
If the intention of the question is to view the contents of the JAR file, then the following java command would help.. (provided, JDK location is added to the environment variables.)
Windows Command prompt> jar tvf yourJarFile.jar
Example:
jar tvf log4j-extras-1.2.17.jar
Reference: http://docs.oracle.com/javase/tutorial/deployment/jar/view.html
I downloaded the latest JDK 7u10. Once you do that, try running your jar, It should execute.

Categories