Jar files just wont run - java

A couple of days ago i installed the latest Java update. in the process i believe something may have gone wrong, as now when i try to open a jar file (double clicking it) it just pops up a terminal window which displays something like:
Cannot find main class "..."
However, if i try to run it straight from the terminal with:
java -jar foo.jar
it will run fine. I have tried doing a full re- install of the JRE and JDK, just for good measure but this has had no effect. Has anyone got any recommendations?
I am using Windows XP with Java 7 update 7.

1. First type java -version from your command prompt, if this command displays the installed JDK version, then you JDK path is perfectly fine.
2. Secondly Perhaps your file associations got messed up. At the command prompt, try running
ftype | find "jarfile"
On my 64-bit Windows 7 computer, that shows
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
You can also change it with ftype:
ftype jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
Also of note was the fact that the application install could be doing a silent install of the JRE, which (silently, of course!) does not associate .jar files correctly. So you have to change the main program install to no longer do a silent install, and also clean up the file associations. After reinstalling the JRE, you could execute the .jar file by double-clicking on it

Related

java how to check version being used by 'jar launcher.app' on Mac OS

I have several .jar files that run successfully when opened with Mac's built in 'Jar Launcher' (Version 15.0.1) but when ran from terminal they error out.
Looking online the error messages might be down to the incorrect version of Java being linked to the terminal version, so I'd like to check if the options set for 'Jar Launcher' and the Java used within terminal are the same.
Does there exist any way to do this?
This question is two years old, but as there is no answer to it, I thought I'd put my two cents here since I've had issues myself, and have made some observations.
It seems that the Jar Launcher doesn't necessarily use the same JVM version as the one shown by the command /usr/libexec/java_home: If there is a JRE /Library/Internet Plug-Ins/JavaAppletPlugin.plugin, then the Jar Launcher will use it and ignore anything in /Library/Java/JavaVirtualMachines.
I've solve my problem of version mismatch between the Jar Launcher and the terminal by removing the JRE:
Go to /Library/Internet Plug-Ins.
Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
Go to /Library/PreferencePanes.
Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.
Source: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm

Given that NetBeans is installed, how can I use ant from the command-line (on Windows)?

I have NetBeans 8.0.2 installed on my Windows 7 (64-bit) machine. I have also the JDK installed (Java SE Development Kit 8 update 66 (64-bit)).
I want to run ant from the command line, but the closest I think I've come to getting it to run is the following:
java -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"
but I got the error
Error: Could not find or load main class org.apache.tools.ant.Main
I also tried the following, thinking that Main.class might be inside ant.jar, but got the same error:
java -cp "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar" -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"
I've spent at least an hour searching online and StackOverflow for the anser. The closest I've found is Compile NetBeans project from command line by using Ant, but it assumes that ant is accessible from the command line already.
To set up ant to work from the command line
Add C:\Program Files\NetBeans 8.0.2\extide\ant\bin to your PATH
Add the environment variable JAVA_HOME with the value C:\Program Files\Java\jdk1.8.0_66 (adjust this if you end up using a different version, of course).
Now that it is set up, simply use ant from the command line normally.
To rebuild the project, for example, simply do the following:
Open a new command prompt
Go to the project directory
Type ant clean jar

How To Change An Association With A .jar File? [duplicate]

I just created a jar file using jdk7. I tried running it but kept getting an error. It turned out it was pointing at a jre6 and not the jre in jdk7. So, I used the following command to change it
ftype jarfile = "C:\path to jre\bin\javaw.exe" -jar "%1" %*
After that, I tried to double click on my jar file again, but it popped up a window asking me to choose a program to open it with. When I chose the same javaw.exe file as above it runs but exits immediately without doing anything. I can run it fine in cmd by doing the java -jar file.jar command. I even tried deleting the .jar registry key, but that just got me back to the point where it asked me to choose a program to open with. I'm running windows 7 ultimate if that matters.
EDIT:
In the registry there are 3 subkeys: OpenWithList, OpenWithProgids, and UserChoice. I've changed all the defaults to the path above except UserChoice which won't let me edit it from regedit. When I delete that and try to run the jar file, it opens up the choose a program to open with window again. For some reason it ignores the other registry keys
OK, I found the answer somewhere else but ran into this issue again so came here via google.
The solution is...
Open up regedit.exe
Either search for "jre6" or follow this: HKLM->SOFTWARE->Classes->jarfile->shell->open->command
Change the Data field to the directory of the javaw.exe file that's in your JDK directory.
For the love of God, don't forget to put the weird [-jar "%1" %*] parts on the end of it.
Enjoy outsmarting Oracle.
Hopefully this'll save some people a bit of time.
This happened to me when I installed the JRE6 plugin for Chrome, though it could happen when installing any other JRE I guess.
I fixed it by going to regedit and searched for jre which brought up...
HKEY_CURRENT_USER/Software/Classes/Applications/javaw.exe/shell/open/command
I changed the REG_SZ
from: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" "%1"
to: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*
When windows asks you for a program to run it against it won't insert the needed -jar argument in the command line.
If it's asking you for the exe in which to run it then that means somehow your JRE isn't associated with the .jar extension. You'll need to modify the .jar file registry entry so that it runs c:\path_to_jre\bin\javaw -jar %1 in order for it to work.
It used to be under File Explorer > Tools > Folder Options > File Types.
Then look for .jar in there. You should find a text field that shows the executable to run and the command line arguments. That's what you want to modify. You can also do it in the registry editor too, but I've forgotten the HKEY variable path. I'm sure this KBA will help:
support_microsoft_kb_950505
Check if the file type jarfile is actually registered with the *.jar extension using
assoc .jar
Seems like .jar is not linked to jarfile.
I'm not sure exactly why none of the solutions worked, but I reinstalled jre7 and it works now.
Isn't it easier to change your java version to you rnew jdk7 by changing the CLASSPATH environment variable? See how here

java virtual machine launcher error: unable to access jarfile

I have downloaded a program to run on windows XP.
According to the instructions, opening the .bat file that includes the command that calls the .jar file would be enough.
Yet the program does not open.
In a friend's computer the program does open.
I have set correctly the java-related environment variables. Java works fine. I have associated .jar files with java sdk.
When calling the command
javaw -Xms128M -Xmx512M -jar filename.jar from cmd
I get a java virtual machine launcher
error: unable to access jarfile
Then I called the same command while being on the folder where the jar is, I have no error, but still the gui of the program does not open.
Any ideas?
On windows support the suggest unistalling and manually re-installing java, but java works fine in any other app.
Try some of the following:
Run directly from the .exe, so "C:...\jre\javaw.exe" -jar
Try java -jar instead of javaw -jar.
Try moving the file. It could be in a permissions sensitive directory.
Also, if the program was compiled using a 64-bit JDK, it might require a 64-bit JRE to run. In that case, you'd need to have a 64-bit OS/JRE to run it.

Java weird behaviour. .jar can't be opened

Whenever I try to double-click a .jar file, it gives me a message saying that it can't locate or load the main class of the file. However, if I try to open the .jar file in the command line like this:
java -jar myfile.jar
Then, it runs. Is it something wrong the the system variables or something? I'm having a lot of trouble with java and uninstalling and reinstalling it again doesn't seem to solve it.
Thanks in advance!
EXTRA INFO: I'm running on Win7 64-bit, with both JDK 7 Update 9 (64-bit) and Java 7 Update 9 (64-bit). It also used to run .jar files just by double-clicking before, I don't know what happened.
Check that these two configurations are in place:
C:\>assoc .jar
.jar=jarfile
C:\>ftype jarfile
jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %*
With the latter pointing to the correct location of your javaw.exe. It should work then.
Double clicking on the jar in Win7 won't pass the -jar flag to the java program, so nothing will happen.

Categories

Resources