Java cannot open executable jar file on Windows 10 (Open with...) - java

So...
When i want to open java executable file by double clicking it, system wants me to select program to open. Before It wasn't like this. it just opened...
when that window pops up, first thing is:
"C:\Program Files\Java\jre1.8.0_92/bin/javaw.exe" -jar "%1" %*
Selecting it nothing changes. I was trying to open it with .bat file and cmd, but it showed me error:
The System cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
i tried MANY different ways to do it, but nothing works :(
Also, I can write programs in Eclipse without any problems.
I am sure, that java files are "Executable jar files".

Related

Making a Java application for Mac users

I succesfully generated a dmg file thanks to this question. My issue now is that when I open the .app file, the program starts and immediately stops.
1) On Mac, how can I get the java error if any?
2) I think that the error occurs because the .app cannot access the files that are within the dmg. The same answer indicates that I could add my files to the .app file. I can do that, but then, how am I supposed to access these files from my application? What would be the path I should use?
3) For GNU/Linux and Windows users, I currently have a .jar file that updates my application by updating the myapp.jar file and some other files. If everything is packaged into the myapp.jar file, how am I supposed to do that?
Thanks for you help!
Have not tested the following but based on what’s described at Bundle Java program for Mac users with maven from GNU/Linux, the following are the steps I would try.
Open Terminal and cd to whatever directory .app is in.
Run find . -name java.
That will return something like foo/bar/jre1.8.0_112.jre/bin/java I guess.
Run find . -name myapp.jar where myapp.jar is the name of the jar you made.
That will return something like foo/bar/myapp.jar.
Run foo/bar/jre1.8.0_112.jre/bin/java foo/bar/myapp.jar.
If that runs, some error message will get emitted that should explain what else is not working.
Note that you can change files inside that .app directory; specifically, you can replace the jar file within the directory.

Java jar file not running

I have compiled my jar file using jar cmf manifest.mf SysInfo.jar *.class and got no errors, but when I try to execute the file by clicking on it nothing happens. I don't even get an error pop up. But when I run the jar using the console it will execute perfectly.
What can I do to make the file run by clicking it?
Try starting it via console using
java -jar yourFile.jar
Don't forget to cd in the directory your .jar file is located before you do this.
EDIT: Sorry, you already said it works like that. Try right click open with.. and then choose open with javaw.exe
If that also doens't work you need to provide more information.

Why i don't have .jar?

When download a file like "example.jar" the file isn't .jar is just a white file.
I tried finding an other .jar file from my java folder and Run As.. it but it just runned cmd for 1 second and then closed it.
Can anyone tell me what to do?
You have to run it via your cmd with command:
java -jar NameOfFile.jar
And you do not see the file extensions, because you most likely told windows in folder options to hide them.

Java program unable to execute from command prompt

I recently installed a java software in my PC and started writing some simple programs. I didn't face any problem while compiling the programs, but while executing it, it shows this error message -
"Windows can't open this file.
File: HelloWorld.java
To open this file, windows need to know what program you want to open it. Windows can go online to lookup it automatically, or you can manually select from a list of programs that are installed on your computer.
I know all the path settings are correct. In fact, there was no problem at all while compiling the program. What can be the problem of this? I even reinstalled JRE and that didn't help. Can someone help me?
Note: I'm using Windows 7 64 bit architecture OS and I'm using command prompt for compilation and execution of the file.
I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't a (click-launchable) executable, and - without some acrobatics - neither is a compiled .class file: you shouldn't expect to double-click either and start your program.
In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.
To just run your code outside your IDE, you can invoke the java VM on the command line:
c:\> java HelloWorld
As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.
But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files. If you're using a specific IDE like Eclipse or NetBeans, use that to refine your search.
When you want to execute the program, you specifiy the class name rather than the file name:
java HelloWorld
Don't use java HelloWorld.java, for instance.

Launch Eclipse Program Exported From File

I already read many questions it the same subject, but none solved my problem..
I know that I can easly launch my app using this command on console java -jar myappname.jar
But what I want is to click on my .jar file exported by eclipse and it launches console with my app inside, do u understand?
I done the export using this configs :
File>Export>Jar File
Selected all the classes of my project
Selected "Export generated class files and resources"
Selected "Export java source files and resources"
Selected "Compress the contents of the Jar File"
Pressed Next
Selected "Export class files with compile errors"
Selected "Export class files with compile warnings"
Pressed Next
Selected "Generate the manifest file"
Selected Seal the Jar
And on "Select the class of the Application entry point:"
I choose my class where is the void main method .
the jar appears on my desktop, but then, when I double click it doesnt launch the console. why??
Thanks in advance!!
Launching a jar by double-clicking the file (or shortcut) will not display a terminal. One workaround is to change the default execute action in your operating system for .jar files to open a terminal and execute the command from within the terminal. A script like the following might do the trick (using Bash):
#!/bin/sh
/usr/bin/gnome-terminal -x java -jar $*
sleep 3
Then right-click on the jar file and choose the script as the default program to run for that file type.
Disclaimer: the above script actually fails for me. It works fine if the command being run in the terminal is "top", so it looks like you may need to tweak this a bit.
It depends on your OS.
If you use Windows, you can create .bat or .exe files. You can find 'how-to-create' tutorials on the internet.
If you use Unix based OS, you can just set the jar to be the executable.
A third party OS probaly has it's own way to set to executable.
This is the only way I am aware of.

Categories