final File classpath = res.resolveResourceAsFile(".exist/classpath.txt");
// create [pkg_dir]/.exist/classpath.txt if not already
final File exist = classpath.getParentFile();
if ( ! exist.exists() && ! exist.mkdir() ) {
throw new PackageException("Impossible to create directory: " + exist);
}
final Set<String> jars = info.getJars();
try {
final FileWriter out = new FileWriter(classpath);
for ( final String jar : jars ) {
StreamSource jar_src;
try {
jar_src = res.resolveComponent(jar);
}
catch ( final NotExistException ex ) {
final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
throw new PackageException(msg + jar, ex);
}
final URI uri = URI.create(jar_src.getSystemId());
final File file = new File(uri);
out.write(file.getCanonicalPath());
out.write("\n");
}
out.close();
}
catch ( final IOException ex ) {
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
}
}