I'm trying to create working .jar file programmatically.
Firstly, I generate .class file and then put it into my JarEntry like this:
FileOutputStream stream = new FileOutputStream(jarFile);
JarOutputStream output = new JarOutputStream(stream, manifest);
JarEntry entry = new JarEntry(token.getPackage().getName().replace(".", File.separator).concat(File.separator).concat(exactName).concat(".class"));
output.putNextEntry(entry);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(pathToClass.concat(exactName).concat(".class")));
byte [] buffer = new byte[1024];
int read = 0;
while(true) {
read = in.read(buffer);
if(read < 0)
break;
output.write(buffer, 0, read);
}
output.closeEntry();
output.close();
in.close();
After that I'm creating .jar file using command:
jar cmf manifest.txt Test.jar javax/xml/bind/*.class
My manifest.txt file:
Manifest-Version: 1.0
Class-Path: ..\artifacts\ImplementorTest.jar
Main-Class: javax.xml.bind.ElementImpl
So size of output .jar files differs on ~100 byte (jar file generated by "jar .." is bigger). And moreover .jar file generated programmatically doesn't work. What the reason of such behaviour?
Known issue is line "Created-By: 1.8.0_20 (Oracle Corporation)" in autogenerated jar file. But I'm talking about jar files with equal manifest and .class files.