0

I am trying to figure out how to package a Jython program as a standalone runnable jar and I have run into a strange problem.

mkdir /tmp/stackoverflow

Get the Jython standalone jar somehow.

wget http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.0/jython-standalone-2.7.0.jar && mv ./*.jar ./jython-standalone-2.7.0.jar

Observe that it runs a Jython repl when not passed a script as a command line argument.

java -jar ./jython-standalone-2.7.0.jar

Produces:

Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_95
Type "help", "copyright", "credits" or "license" for more information.

When I unpack the jar and repack it, it complains about a missing manifest.

mkdir unpack
cd unpack
jar -xf ../jython-standalone-2.7.0.jar
# repack jar
jar -cvf output.jar ./*

This time java -jar output.jar produces the following output

no main manifest attribute, in output.jar

As it turns out the contents of output.jar and jython-standalone-2.7.0.jar differ, but I think this this is just the nature of the beast when it comes to compression

$ diff output.jar ../jython-standalone-2.7.0.jar
Binary files output.jar and ../jython-standalone-2.7.0.jar differ

The paths contained within do not differ, however (the following command produces no output)

$ diff <(jar -tf ../jython-standalone-2.7.0.jar | sort) <(jar -tf output.jar | sort)

What the heck is going on? Why isn't the new jar honoring the MANIFEST.MF it contains?

Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65

1 Answers1

0

As it turns out, the jar needs to be explicitly told where to look for the MANIFEST.MF file.

jar -cvmf META-INF/MANIFEST.MF output.jar ./* 

produces a jar that can be run just like the original one. This still leaves the question of what file actually changes when a `MANIFEST.MF` file is specified as an argument.

Can't execute jar- file: "no main manifest attribute"

Community
  • 1
  • 1
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65