How do I mark a .jar file as executable on Xubuntu 13.04?

24,747

Solution 1

Assuming the file in question is in your $HOME (just move it with the GUI otherwise), open a terminal (that much should be easy :) then run this command:

chmod a+x jarfile.jar

Change jarfile.jar to the actual name of the file in question of course. If that gives you an error, the file is probably not owned by your user, so try again with sudo:

sudo chmod a+x jarfile.jar

Solution 2

Jar files are supposed to be executed like I've shown below (assuming you have configured JRE/JDK in the execution search path):

java -jar /path/to/jarfile.jar

You CANNOT directly execute a JAR file even if you add the execute bit. By itself bash is simply not able to understand it.

A simple shell script will be ideal to run Minecraft, for example:

#!/bin/bash
java -Xms1024M -Xmx1024M -jar /path/to/mincraft.jar
Share:
24,747

Related videos on Youtube

Ben
Author by

Ben

Just a Xubuntu user that knows a small amount about terminals and is trying to learn.

Updated on September 18, 2022

Comments

  • Ben
    Ben almost 2 years

    I'm trying to get the minecraft.jar file to execute , but the check box won't come up when I go to Properties > Permissions. I don't know much about the terminal and its commands so if someone could post a simple step by step solution on how to mark it that would be great. People keep saying to use a chmod command but I have no idea what that is, so you are forewarned if I say "over my head".

    • RobotHumans
      RobotHumans almost 11 years
      jars don't need to be executable. you can launch them with an interpreter just like python and have a launcher script (which I think is the generally accepted practice).
    • Richard
      Richard almost 11 years
      Have you tried right clicking the jar, and selecting "Open With > OpenJDK (or whatever java)"?
  • Ben
    Ben almost 11 years
    I have had it work on 12.04 before but not this time so I don't know what to do.
  • kiri
    kiri almost 11 years
    Files in your home directory should not be owned by root
  • kiri
    kiri almost 11 years
    @Ben Is it on your system drive or a external disk?
  • Ben
    Ben almost 11 years
    It worked perfectly!
  • kiri
    kiri almost 11 years
    You are able to mark it as executable then open it with a double click. You just need to associate the MIME type with Java JRE
  • Ben
    Ben almost 11 years
    and I need 15 rep
  • terdon
    terdon almost 11 years
    @minerz029 that depends on who put them there. There is nothing that stops them from being owned by root. Try sudo touch foo; ls -l foo.
  • Terry Wang
    Terry Wang almost 11 years
    This is desktop environment specific, not flexible if JVM arguments need to be passed;-) But you are right anyway, double click executes jar files in DE/WM.
  • terdon
    terdon almost 11 years
    WHat about self-extracting jar files?
  • kiri
    kiri almost 11 years
    I said should not. With normal use, nothing in your home folder should be owned by anyone except yourself.
  • terdon
    terdon almost 11 years
    @minerz029 I understood that to be a prescriptive should rather than a hypothetical :). Anyway, that's not entirely true, there are various things that can end up in your $HOME, try find ~/ -user root, you might be surprised.