config.put("jvmArg." + i, "-Dfile.encoding=UTF-8");
}
// create an executable jar with main runner and zipFile
final FileOutputStream fileOutputStream = new FileOutputStream(execFile);
final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR, fileOutputStream);
{ // distrib
os.putArchiveEntry(new JarArchiveEntry(distributionName));
final FileInputStream in = new FileInputStream(zipFile);
try {
IOUtils.copy(in, os);
os.closeArchiveEntry();
} finally {
IOUtil.close(in);
}
}
{ // config
os.putArchiveEntry(new JarArchiveEntry("configuration.properties"));
final StringWriter writer = new StringWriter();
config.store(writer, "");
IOUtils.copy(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")), os);
os.closeArchiveEntry();
}
{ // Manifest
final Manifest manifest = new Manifest();
final Manifest.Attribute mainClassAtt = new Manifest.Attribute();
mainClassAtt.setName("Main-Class");
mainClassAtt.setValue(runnerClass);
manifest.addConfiguredAttribute(mainClassAtt);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
manifest.write(baos);
os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF"));
IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), os);
os.closeArchiveEntry();
}
{ // Main + utility
for (final Class<?> clazz : asList(
ExecRunner.class,
Files.class, Files.PatternFileFilter.class, Files.DeleteThread.class,
Files.FileRuntimeException.class, Files.FileDoesNotExistException.class, Files.NoopOutputStream.class,
LoaderRuntimeException.class,
Pipe.class, IO.class, Zips.class, JarLocation.class,
RemoteServer.class, RemoteServer.CleanUpThread.class,
OpenEJBRuntimeException.class, Join.class, QuickServerXmlParser.class,
Options.class, Options.NullLog.class, Options.TomEEPropertyAdapter.class, Options.NullOptions.class,
Options.Log.class
)) {
final String name = clazz.getName().replace('.', '/') + ".class";
os.putArchiveEntry(new JarArchiveEntry(name));
IOUtils.copy(getClass().getResourceAsStream('/' + name), os);
os.closeArchiveEntry();
}
}
IOUtil.close(os);
IOUtil.close(fileOutputStream);