I know that to execute a file, I use the .
command, then the file name with a space between them. But I'm trying to execute a .jar file using the .
and it does not work. I went into the properties and marked it as executable and made it run with Java.
Is there a way to execute a file with Java in the Bash Terminal?
I am trying to execute the Minecraft.jar file.
The
.
syntax can only be used to run (by "sourcing") shell scripts.You'll need to use the
java
command to run a.jar
file:If you don't have java installed, you can fix that by installing the
default-jre
¹ package. You can see if you already have java installed by running in a terminal:[1]: This will install the default openjdk Java runtime. You can use
openjdk-8-jre
, oropenjdk-7-jre
, oropenjdk-6-jre
instead, if you prefer - whichever is available on your version of Ubuntu.Linux is perfectly capable of running a foreign binary, like a JAR file. This is how Wine works, for example. To run JAR files as executable do the following in a console
Cd to your JAR file and change it to executable (you can also do this through file properties in Nautilus)
Run your jar file just as if it was any other binary executable or shell script
Note: Be sure you have binfmt_misc linux kernel module loaded. If you use your custom compiled kernel without this module, binfmt-support won't work.
If it is an executable jar, then
Not all jar-Archives contain an executable class, declared to be started in the Manifest file, but if there is, this will work.
Btw.: You don't start most programs from the shell with the dot. The dot is a shortcut for
source
, and it only works in the bash and some other shells, to include a script in the scope of the current session.A compiled binary xybin is simply started with its name if it is in the path:
or, with its absolute path:
or with its relative path:
or if you happen to be in the directory of the file, with this relative path:
The file has to be marked executable for you (see: chmod). All of the above is true for shellscripts too, but they often have an extension .sh, and you can start a shellscript by invoking the interpreter, and then it needn't be marked executable:
If you don't want to start a new bash, you can use source, and you do so, to consume function definitions, aliases and variable settings.
You might as well want to make a nice entry for the application in Unity. execute the following commands:
In the window that pops up, copy and paste the following:
You might need to log out and back in to see the effects. :) Also you need to search the internet for a nice lookin Minecraft icon since they don't provide one with the download..
Type the following command:
This way your ".jar" file will execute.
Install jarwrapper. After that (and by adding the executable bit) you can start the jar file just by entering the jarfile name.
This works by using
binfmt
to add support for a new binary format to the kernel.New answer to an old question
Executing a jar file using the regular syntax
./app.jar
(instead ofjava -jar
), is easy to achieve, as explained here: how to create executable jars.Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it "executable".
Here is a simple example of turning a "normal" jar into an executable one:
With this, you can now run
./executable.jar
instead ofjava -jar original.jar
. This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.if u want to install your jar with specific java version Specify the java directory also