Java minecraft jar extension - java

I know minecraft is written in Java, and that Java cannot be changed to exe files. Yet, when I download minecraft, it says minecraft.exe and runs as an exe file, not a CLASS file. Can someone explain it to me?

The Minecraft.exe you download is unrelated to the actual Minecraft game, it's simply a launcher which is used to download and run the Minecraft version you select.
The version of the game you're running is downloaded to .minecraft/versions/<VERSION>/<VERSION>.jar. e.g. .minecraft/versions/1.6.4/1.6.4.jar

MrLore's Answer above is correct. If you download the app from minecraft.net, you are probably going to get the .exe if you download the first link there; there is also another option for downloading it as a jar, at which point you can run the following in the directory you've downloaded the java package in:
java -jar minecraft.jar
This is necessary for operating systems that do not have built-in .exe support, such as OSX or any UNIX-based system.

Related

How does importing libraries in Java work

I'm starting to program in Java and I can't quite understand how importing libraries works.
Suppose I need to import a library in order to be able to write a specific program. I save it in my PC.
How is someone who does not have the same library on their machine supposed to be able to run the program? This is probably a silly question, but I really am new to programming.. Thanks.
They need a java runtime (JRE) installed.
Third party libraries like apache commons, accompany your application jar.
myapp.jar
lib/apache-commons.jar
lib/ido.jar
The myapp.jar (zip format) contains a METAINF/MANIFEST.MF containing an entry
Main-Class: ...
Class-Path: lib/apache-commons.jar, lib/ido.jar
And with that myapp.jar is an executable jar.
A build tool like maven can be used to build such a distribution: take care of library versions (dependencies), preparing the manifest, generate to output folder.
"Someone who does not have the same library on their machine" is a wrong concept. A machine has to have the Java Runtime Environment (JRE) installed on it in order to run a Java program (i.e., to execute the .class file). The JRE contains all the Java libraries. Therefore, every machine running Java has every library that you can possibly use in your program.
Importing a library in your program is basically instructing the compiler to include that library in the program. You don't really save the Java program on your PC with the libraries in it. It's just a set of instructions. These instructions are given to the Java platform on any machine the program is run on. While running the program, the JRE on that machine uses the libraries as instructed in the .class file.
I hope I could make it clear to you.
In addition to the above answer, have a look at the libraries, which are found by:
right click on project
build path
configure path
libraries
You can check weather the JRE is added to your project or not
If it's not present click on add libraries and add it

How do I make a final executable file for my Java program?

I created a tic-tac-toe game in Java. It runs fine on Eclipse.
How do I compile this file (which is currently a .java file) to the standard file format of Java applications, so it can be run from the desktop like a normal program?
What is the standard file type for the final executable Java application? What should be the file type if I want people to easily and without any computer knowledge run my program on their computers?
with eclipse right click on your project. then export it as a runnable .jar file.
Project Right Click > Export > Runnable .jar File.
First choose your project under "Launch configuration", then choose your destination.
After that click finish. Your program should be in your destination folder. Double click to start (just like an .exe file)
For example: If you export it to your desktop, and you name it "TicTacToe", the file on your desktop is "TicTacToe.jar" - ".jar" is your executable file
Done
You have to compile your java class first
javac TicTac.java
and then execute it
java TicTac
Note: that here you provide the name of the class with the main method!
As the other answers indicated, you can create an executable jar using eclipse (or a number of other tools). What these tools are doing under the hood is defining the Main-Class: attribute in the jar's manifest.
In Windows, your users can double click on an executable .jar to launch it, as long as the file associations are configured correctly. However this may not be obvious to windows users who are trained to expect some sort of .exe extension.
To solve this, you could use launch4j to wrap your executable jar in a windows executable. Note: this doesn't change your java application into a native application (it still requires the JVM, etc), it simply makes it launch more like a native application.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS works on Windows, OS X & *nix.
Note that JWS is more effort for us to deploy (it involves not only Jarring and signing the code, but creating a JNLP launch file and a page on the net or network to check that Java is installed & serve the files to the user), but is super easy for the end user.
If there is a JWS deployment, the Jar does not have to be an 'executable Jar' as described in the other answers.
The command should be javac yourFile.java from you command prompt and then after compilation, class file is created. You can run it using java MailClassName
You can find a good tutorial on using javac and java commands here.

.jar file will not open

I have created an executable jar file and have tried both the extract and package option for generated .jar. It creates it but when clicking on it nothing happens. I tried naming it the same as the class file or the project file too. This didn't happen before I don't know why it stoped working. It won't run even a simple hello world file. However a .jar file I made a while ago will run. I compiled with Eclipse, and running it with java -jar in cmd does work. I am running Windows 07. Any help would be greatly appreciated
Edit: tried uninstalling and reinstalling Java and Java JDK
you should check the application used to open the jar file. it should be java or javaw and should be called with -jar parameter. What Operating system are you using?

How to convert exe application to jar file?

I have exe file called Myapp.exe. Now I want to convert .exe to jar file. That jar file should also work in NON JAVA system. I don't have any idea to implement it. Can anyone please suggest me how to do it?
Direct conversion not available !!!
because they are in entirely different platforms.
Meeting your requirements is impossible for two reasons.
1) You cannot change an EXE to a JAR file.
2) You cannot run a JAR file on a system that doesn't have Java installed.
If you want to run something on a (Windows) system with no Java installation, it needs to be an EXE ... or something else that doesn't require Java.
(It might help if you explained why you think you need to do this. Perhaps there is an alternative set of requirements that are not impossible to meet.)
why i am doing all those stubs is for making my jar has to work in java not installed system.
It needs to be an EXE then!
I have an jar.It is working fine in java installed system.My task is to Bundle jre inside jar(Not along with jar(i.e we can put jre and jar in same folder to run a jar as given in following url mindfiresolutions.com/… ))Because i have to give jar file only to client,in such a way that they can use this Myapp.jar in non java system also.But,i don't know how to bundle jre inside jar.I Don't how to run jre inside jar?
Ermm ...
Is it possible?
No. You cannot embed a JRE inside a JAR file in any way that would allow it (the JAR file) to run your Java code without first installing Java. (And installing Java would defeat the purpose of embedding the JRE ... of course.)
But what you can do is create an EXE file which has a JRE and a JAR embedded in it. And there are tools for doing this. Here's the canonical Question on how to do it:
How can I convert my Java program to an .exe file?
I think you need to read the Oracle documentation on what a JAR file really is, and how Java programs are normally executed. That will help you understand what is feasible ... and what is nonsensical.

Is there a tool which will package a copy of the JRE with my application so that it can run regardless of whether or not the user has Java installed?

This is my first brush with actually distributing a Java application. I'm coming from a Python background, which has a fantastic set of tools for distribution called PyInstaller, and Py2App. Both of these package up a copy of the Python Interpreter along with the application so that there's nothing to install for the end user. They simple see an .EXE or .app double click it, and the program starts.
So far, I have been unable to find a similar tool for Java. The idea behind this app is that it's stored on a flashdrive so it can be run without installing anything on the host machine.
I've found decent tools for Windows. For instance, Launch4J appears to do the trick, but it's for windows only. I'm desperately in need of similar functionality, but for making an app.
Has anyone faced this conundrum before? Are there any tools which I could use?
Have a look at install4j, it's a multi-platform Java installer (and launcher) builder. You can bundle a JRE with your installers.
Disclaimer: My company develops install4j
Lets assume you are distributing via a .zip file
You could drop a copy of the JRE in your app directory, then create a .bat and .sh script that will run the app with a java command using the JRE that is in the same directory.
There is probably a better tool to do this but this is one way it could be achieved.
A super simplified example .sh script
#!/bin/bash
jre/bin/java myapp.jar
Would run myapp.jar using the JRE in that location. In reality you would want to put checks to make sure the JRE exists.
the app folder:
myapp/
jre/
start.sh
start.bat
myapp.jar
the jre would be an actual JRE instance.

Categories

Resources