Laurent Mesguen
Laurent Mesguen

Reputation: 394

Difference betwen these two command lines to execute .jar?

When I execute a .jar with this command line (it's a command found in a script):

./MyJar.jar AUTO

I have these errors :

./MyJar.jar: 1: ./MyJar.jar: PK: not found
./MyJar.jar: 2: ./MyJar.jar:: not found
./MyJar.jar: 3: ./MyJar.jar: ��H: not found
./MyJar.jar: 4: ./MyJar.jar:: not found
./MyJar.jar: 5: ./MyJar.jar: Ant-Version:: not found
./MyJar.jar: 6: ./MyJar.jar: Syntax error: "(" unexpected

But when I execute with this command line, it works:

java -jar MyJar.jar 
  1. My first question is : "What's the difference between these two command lines ?"
  2. My second question is : "Why am I not able to execute MyJar.jar with the first command line ?"

Upvotes: 0

Views: 156

Answers (2)

Laurent Mesguen
Laurent Mesguen

Reputation: 394

I have found the answer to my second question. To be able to execute my jar this way:

./MyJar.jar AUTO

I need to install the binfmt-support package :

sudo apt-get install binfmt-support

As mentionned on this topic : https://askubuntu.com/a/291514

Upvotes: 1

aze2201
aze2201

Reputation: 559

normally if any file trying execute directly by Linux terminal file header information should be identified by OS. for example:

#!/bin/bash
echo "Hello World"

or

#!/usr/bin/python
print "Hello World"

you can see OS will understand 1st script should be run by /bin/bash interpreter and 2nd is python interpreter.

it seems OS don't under understand how to execute your ./MyJar.jar file. but jar can directly understand your file content

Upvotes: 1

Related Questions