Run .jar applications per double-click with OpenJDK doesn't work - java

I wrote a java app called "MyApplication" in IntelliJ with OpenJDK. It displays a JFrame on the desktop until the user closes it. I've exported it as a .jar file with default artifact options. But if I try to start it with a double-click unfortunately nothing happend.
I tried to change the application to start with to java.exe and javaw.exe from the OpenJDK installation folder but that doesn't help. I also checked my environement variables from my windows system. I set them all like every webside from google says, they have to be correct. If I run javaw MyApplication.jar from command prompt nothing happens too. But if I run java MyApplication.jar from command prompt following error message occurs:
Error: Could not find or load main class MyApplication.jar
Caused by: java.lang.ClassNotFoundException: MyApplication.jar
After a research I found out that a classpath could be missing. But I do not use any external libraries or other stuff. Just the OpenJDK and a JFrame object from the java.swing library. A second reason could be that there is a mistake in the 'Manifest.mf' file but that was created by IntelliJ and I checked it. This file should be ok. Here is a preview:
Manifest-Version: 1.0
Main-Class: de.java.configuration.Main
deis the first package in src folder. java the second and so on. Main is the java class where the main method is included. If I set a -jar between java / javaw and MyApplication.jar in command prompt it runs perfect.
At this moment I want to ask an other question. What exactly -jar means as java parameter in command prompt?
I can't open other .jars too. The same behaviors occurs.
So my target is that I can double-click the .jar on my desktop for example and the app opens. Like javaw -jar MyApplication.jarbut with a double-click on the software icon. How is it possible?

Related

Cannot open .jar files with java installed (windows 11)

Environment: Windows 11
Problem: cannot open .jar file(the MARS assembly language simulator)
Hello, I am currently trying to install the MARS assembly language simulator. It is a .jar file so I downloaded java to open it. However, I still can't open the file even with java downloaded.
I checked if java was installed using my cmd:
Command prompt showing java successfully installed
I tried double-clicking it did not work. So I right-clicked it to open with other apps. But I did not see java in the given options.
Cannot find the java option to open the file
Thank you so much for helping!
Use your prompt
CD into the directory with the jar
then execute
java -jar Mars.jar
...any more troubles , open file properties tab with right click on the jar and check permissions to execute the file.
Installing Java usually means installing a JVM, which is a Java Virtual Machine. You won't be able to launch files from a Windows context menu like this, because "Java" is not a program that opens files.
Instead you need to:
Either a terminal and call javaw.exe with the parameters -jar and your .jar-file. E.g.:
C:\your\java\binaries\javaw.exe -jar -SomeJarFile.jar
Or add the Java installation to your environment variables, then you can call javaw.exe without providing some specific path

Can't run .jar classes from .sh on Linux that work on Windows via .bat

I'm having a strange issue trying to run classes from an executable .jar file on Linux that none of the existing question threads I've sorted through seem to be able to resolve. I'll preface this in that I've never had to use Linux before and am only using it in this situation out of necessity, so it's possible I have overlooked something simple that I just didn't know could be causing the problem.
I can launch the classes from my .jar file without any issues on Windows via a .bat file with the following settings:
start "MyServer1" java -classpath ./*;Server.jar infoServer/StartInfoServer
start "MyServer2" java -classpath ./*;Server.jar loginServer/StartLoginServer
start "MyServer3" java -classpath ./*;Server.jar chatServer/start
start "MyServer4" java -classpath ./*;Server.jar gameServer/start
However, when I move to trying to launch these classes from the .jar on Linux, I get a "could not find or load main class" error. My .sh file is set up like this, and is placed in the same directory as my .jar file:
echo Starting Servers
java -cp Server.jar infoServer.StartInfoServer
java -cp Server.jar loginServer.StartLoginServer
java -cp Server.jar chatServer.start
java -cp Server.jar gameServer.start
echo All Done Starting Server
I've used ls from the Terminal to verify the .jar and .sh were being recognized as existing where they should be. (For future note, I'm using the Terminal from inside the directory containing my files.) I've made sure to make use of chmod to be sure both the .jar and the .sh have read/write/execute permissions and used ls -l to verify those permissions were indeed present. I've tried various forms of explicitly defining the classpath, such as using "/home/machine/Desktop/Folder/MyJar.jar", using pwd from the Terminal to ensure I'm getting the filepath correct. I've checked over my Java compatibility. (1.7.0_65 on Linux, 1.8.0_45 on Windows, with the .jar being created in Eclipse using 1.7 Compliance settings.) I can use unzip MyJar.jar from the Terminal and it will properly extract all my class files, allowing me to verify that my .jar isn't corrupted on my Linux machine and that the paths to the classes I'm trying to run are still the same on Linux as they are on Windows.
I do apologize if this is just a problem of inexperience overlooking something, but I can't think of or find any indication of what the problem could possibly be.
EDIT:
I've updated the question with some screenshots related to the problem:
https://gyazo.com/0ae2a2701aae734db21ef7c29200283b - General File Setup.
https://gyazo.com/d735d9cee57b4a92078c4b624d012b8c - Running the Shell via Terminal.
Other notes: jar -tf Server.jar works from the Terminal but not from inside the Shell script, which leads me to believe this may be some kind of visibility or pathing error, but I can't find any reason why that would be the case.

Java .jar executable not opening (on double click)

I wrote a little command-line game that has 5 classes: the main class "DiaDia.class", and the others "Partita.class", "Comando.class", "Stanza.class", "Attrezzo.class".
Then i created a diadiamanifest.txt file so:
Main-Class: DiaDia
ending file with a new line.
I tried to make a DiaDia.jar file with 2 different commands:
jar cvfm DiaDia.jar diadiamanifest.txt DiaDia.class Partita.class Comando.class Stanza.class Attrezzo.class
jar cvfe DiaDia.jar DiaDia DiaDia.class Partita.class Comando.class Stanza.class Attrezzo.class
In both cases the generated DiaDia.jar file runs well with the command:
java -jar DiaDia.jar
but does nothing with a double click on it.
I set properly the file association of .jar extension to
C:\Program Files\Java\jre7\bin\javaw.exe
I run Windows 7 Home Premium x64, with jre7 update 76 and jdk1.7.0_76.
I wrote a little command-line game
That's the problem then.
javaw.exe is designed to run GUI applications - it doesn't allocate a console. If you change the file association for .jar to run java.exe instead, it will launch a console and your app will run. On the other hand, anything else that's designed to run as a launchable jar file - most of which will have GUIs - will end up launching a console even if you don't want one.
Alternatively, change your game to not need a console, or just run it from a command line using java -jar ... which, as you've already said, works fine.

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.

Running program as jar file

I have Java GUI application in Java SE version 7 which I run on Windows 7 64 bits. When I try to run it clicking on jar file the pop up Window is saying 'Cannot find the main class or load it:...'. When I run the same jar file via command line in this way: java -jar app.jar' it works fine. If you try to run it in this way: 'java app.jar' it throws the same error. On Eclipse IDE it works fine. The jar file has been created by the Eclipse IDE as Running jar file. I have created one more project with simple GUI. It has the same problems as above example. What might be the problem? My goal is to run the app once you click on the jar file.
Best regards
Sounds like on your system the .jar extension is registered to run with Java6 and your application needs Java7.
On the commandline type the following command to find out how the .jar extension is registered:
assoc .jar
It will show something like this:
.jar=jarfile
(Note: on your system it might be a different type name. Anything after the = is the typename that you need to use)
Now you need to find out which command is associated with the typename jarfile by using:
ftype jarfile
On my system it shows:
jarfile="C:\Programme\Java\jre7\bin\javaw.exe" -jar "%1" %*
If that is not pointing to a Java7 installation you need to change that e.g. through the ftype command or through the Control Panel.
You might also be able to switch the default Java VM by using the "Java" applet in the Control Panel.
You need to make a manifest file, under the Meta-INF folder. If there's already one there, add the line
main-class: [class name].class
And try that (not sure if there's supposed to be a space after the colon)

Categories

Resources