4

I extracted the files from a dacapo benchmark jar.

jar -xf dacapo-2006-10-MR2.jar

Then, I got this folder

dacapo-2006-10-MR2

I tried to recombine them together in this way:

jar cmf dacapo-2006-10-MR2/META-INF/MANIFEST.MF my-dacapo.jar dacapo-2006-10-MR2

But I got an error when I tried to use the new jar:

java -jar my-dacapo.jar -s small antlr

Exception in thread "main" java.lang.NoClassDefFoundError: Harness
Caused by: java.lang.ClassNotFoundException: Harness
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Harness. Program will exit.

I am not familiar with the jar files. Could anyone do me a favor? Thanks!

@Bohemian It seems your solution doesn't work here, see below

> zip -r my-dacapo dacapo-2006-10-MR2
> mv my-dacapo.zip my-dacapo.jar
> java -jar my-dacapo.jar -s small antlr

Invalid or corrupt jarfile my-dacapo.jar

Thanks anyway.

JackWM
  • 10,085
  • 22
  • 65
  • 92

4 Answers4

3

A jar is just a zipped file with an extension of ".jar"

Zip up your files and rename the .zip to .jar

Bohemian
  • 412,405
  • 93
  • 575
  • 722
1

The Jar tool provides a u option which you can use to update the contents of an existing JAR file by modifying its manifest or by adding files.

The basic command for adding files has this format:

jar uf jar-file input-file(s)

In this command:

  • The u option indicates that you want to update an existing JAR file.

  • The f option indicates that the JAR file to update is specified
    on the command line.

  • jar-file is the existing JAR file that is to be updated.

  • input-file(s) is a space-delimited list of one or more files that you want to add to the JAR file.

Any files already in the archive having the same pathname as a file being added will be overwritten.

More detail: https://docs.oracle.com/javase/tutorial/deployment/jar/update.html

Channa
  • 4,963
  • 14
  • 65
  • 97
0

first of all go to the directory where that file are unzipped .then write command.

jar cvf (class which u want to insert).class (or folder which u want to insert)

it will generate executable jar file

Dipen Jogi
  • 151
  • 1
  • 7
0

If you use eclipse, there you can get your jar by follow these steps and create manifest

Also you might need to read this(you might have not define your main class in manifest file)

Ruwantha
  • 2,603
  • 5
  • 30
  • 44