Okay so I have been coding a game for a while now and I am hoping to release its alpha just one problem. I don't know how to export it and run it. Please note that all my code works fine. So when I export it I export it as a Runnable jar file once I do so I set it and have tried both exporting it as .jar and .exe. Once I exported it I tested it by clicking the resulting file but it doesn't open the application but rather it opens it in eclipse encoded. Please help I may just be an idiot.
you have to try to launch it with:
java -jar yourrunnable.jar
If you plan to run on windows and you want a .exe file, try to check this SO question: How can I convert my Java program to an .exe file?
or if you want to target a mac, you can have a check here:
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
Basically any platform you target you have some customization in order to achieve a seamless run. Anyway the most cross platform solution is the Java -jar way.
I had the same problem with .jar files not opening on a double click. It turned out that I had two versions of Java installed (Java 6 and 7). Uninstalling Java 6 from Control Panel-> Uninstall a Program was what finally allowed .jar files to open on a double click without using the command window.
What is listed in right-click-> Open With ? Is some other program listed as the default program ? Is a Java Runtime listed ? If a Java Runtime is listed, you can open with it, and make it the default program to run with.
Right Click -> Properties -> Change -> C:\Program Files\Java\jre7\bin\javaw.exe
For Java 8 use below
java.exe -jar myFile.jar
Related
So, I have a program in a .exe file that needs Java 8 to run. I have Java 16 installed. I tried installing Java 8 with a Java installer that came bundled with the program but it is still run with Java 16. I have seen solutions that solve that problem but only with .jar files (using Java.exe CLI to launch the file with different Java path). I have lots of apps that run on newer Java versions so I can't uninstall Java 16.
The program is here, it's all in Ukrainian but there is Google Translate (press the red button to download zip file, clear on VirusTotal except some antivirus flagging a runtime packer, Інсталяція Polynom.txt is the README)
UPDATE 1: in reply to a comment in an answer, the contents of the cmd file:
set JAVA_HOME=C:\Program Files (x86)\Java\jre1.8.0_291
set PATH="%JAVA_HOME%\bin;%PATH%"
D:\Distributive\Polynom\Polynom.exe
So, you need to set JAVA_HOME (location where you installed JAVA 8, must have a directory bin and lib), and optionally add that to your PATH.
Open CMD.EXE
set JAVA_HOME=C:\path\to\Java
set PATH="%JAVA_HOME%\bin;%PATH%"
In the above file, java.exe is in C:\path\to\Java\bin\java.exe.
Then run the program from CMD.EXE
If that works, create a CMD file containing the above text - when you want to start the program, start the CMD file.
notepad c:\Users\jdoe\myprogram.bat
Copy the above two set lines into that file followed by the full path to the program you want to run. The file would look something like this:
set JAVA_HOME=C:\path\to\Java
set PATH="%JAVA_HOME%\bin;%PATH%"
C:\Users\jdoe\MyProgram.exe
Tip: If you want the icon of the program, create a shortcut of the CMD file
Right-click the CMD file, click New > Shortcut
Right-click the shortcut, click Properties, click Change icon
Navigate to the EXE file and select the icon you want
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
Is it possible to create a executable jar file coded in java12 while java8 is still installed?
We use java8 in university but privatly im coding in 12 and so i need to find a way to run a private coded program through a jar file (created with artifacts through intellij) but still keep the java8 installment for university.
i tried this command
start javaw -jar jogurtLaunch.jar
and i tried rightclick and 'open with' and using the java12 exe (both java.exe and javaw.exe), but nothing happens except for the windows cmd prompt popping up for a few milliseconds in case of the exe and a jvm error ('Error: A JNI error has occurred, please check your installation and try again') popping up in case of the command.
Also i'd prefer a solution that is usable on all computers and not just for java12 development pcs.
Is there a way or do i have to code it in java8?
What the title says really. I've tried exporting it to a Runnable Jar File, checked the Manifest.MF, and tried running it with Java multiple times but with no luck. However, it does work when I navigate to the file using the command prompt and launch is using java -jar Name.jar. This shows it works but I just can't get it to launch by double clicking.
I guess you're trying to launch a commandline-app. This kind of application can be launched by double-clicking aswell. There's only one problem: Java doesn't create a commandline-window by default and instead uses the commandline of the parent-process of the JVM, which in case of double-clicking doesn't own a console-window. In other words: the output to the console gets lost somewhere in the depths of your OS and the JVM and the program hangs as soon as any input is expected.
(Assuming your on Windows OS), if you right-click on it, do you see the option 'Open with' and then 'Java (TM) Platform SE binary', or something like that? And if you opt to open with that, does it execute?
If so, then you've probably set .jar files to open with a different application by default. For example, I have my computer set up to open .jar files with jd gui as the default application.
When I double click the jar file, the GUI program doesn't start by itself. Instead I have to open the Command prompt and then type java -jar abc.jar and only then it starts up. Why is that? What do I need to do to avoid this?
Is it that I have some problem with the default jar file opener? What should be the jar file opener?
if nothing happens, then don't you get any error message like could not find main class or something similar?
I would suggest check your jar file association. On command-line type:
ftype | find "jarfile"
Sometimes, even resetting it works, find out the absolute path of JRE and run the command:
ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
This would most probably solve your problem.
Maybe you would like to follow the instructions in this post: Running JAR file on Windows.
Just a minor note though. The exact syntax for me to work was in my Windows XP:
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe -jar "%1" %
If your jar file opens successfully from the cmd line means its a correct jar and everything is in place. Now you have to associate the correct program with it.
Right click on the jar -> Open With -> Go to JRE/BIN/javaw.exe -> OK
Now all the jar files are associated with the correct program. Try now!
I had this same problem. In my case, I think it was because I was using Scanner(system.in) input.
By default, Windows opens .jar files with javaw.exe (thanks Johnydep), the version of java that runs without a terminal.
In my case, running javaw -jar myJar.jar didn't work either.
I ended up writing a tiny batch file that uses the regular java.exe: java -jar myJar.jar
Which operating system? You need to configure your default applications. In KDE this is under System Settings -> Default Applications. For Gnome, Mac, or Windows you will have to google to find where to set it.
On windows: right click on jar -> open with -> choose programm... -> select "Java (TM) Platform SE binary".
Optionally, check the "Always use the selected programm to open this kind of file".
Navigate to:
File->export->Java->Jar file->Next->use the tree to select the files you want to be included in your jar->Next->Next->
now i guess comes the part you have missed
at the bottom under "Main Class" click "Browse"->selcet the class you want to run when double click->press ok->finish.
should work now.
I couldn't find this answer anywhere and it solved my problem after i had same issue.
I had the same problem in Linux with a jar generated by Intellij, and I find that it's the problem of permission, the jar file's permission is
"-rw-rw-r--", you need to add the permission of execute:
$chmod +x xx.jar, and double click.
Maybe it is because your jar is not an executable jar due to which you cannot execute it directly by double clicking on it.