Example 2

Create a Jar archive from the class files in the directory hierarchy under d1, using the manifest file /tmp/my_manifest.txt. The archive will be put in directory d.

JavaScript

new JarTF(). addSource(new DirectoryAndFilter(d1, new EFileNameExtensionFilter("class"))). setManifest( new File( Packages.java.lang.System.getProperty("java.io.tmpdir") + File.separator + "my_manifest.txt")). setTarget( new FutureFile(d, "d1-1.0.jar")).run();

Example 3

Create a Jar archive from the class files in the directory hierarchy under d1. Use a manually created manifest. The archive will be put in directory d.

Groovy

import java.util.jar.* import java.text.SimpleDateFormat import org.entityfs.util.filter.entity.* import org.schmant.arg.* import org.schmant.support.* import org.schmant.task.jdk.jar.JarTF // Create a Manifest object def m = new Manifest() def attribs = m.mainAttributes // This attribute must be set! See the Manifest Javadocs. attribs[Attributes.Name.MANIFEST_VERSION] = "1.0" // Add information on the build date attribs[new Attributes.Name("Build-date")] = new SimpleDateFormat("yyyy.MM.dd").format(new Date()) // ... and on the project attribs[new Attributes.Name("Project")] = "MyProject" new JarTF(). addSource(new DirectoryAndFilter( d1, new EFileNameExtensionFilter("class"))). setManifest(m). setTarget( new FutureFile(d, "d1-1.0.jar")).run()

JavaScript

// Create a Manifest object m = new Manifest(); attribs = m.getMainAttributes(); // This attribute must be set! See the Manifest Javadocs. attribs.put( Attributes.Name.MANIFEST_VERSION, "1.0"); // Add information on the build date attribs.put( new Attributes.Name("Build-date"), new SimpleDateFormat("yyyy.MM.dd").format(new Date())); // ... and on the project attribs.put( new Attributes.Name("Project"), "MyProject"); new JarTF(). addSource(new DirectoryAndFilter( d1, new EFileNameExtensionFilter("class"))). setManifest(m). setTarget( new FutureFile(d, "d1-1.0.jar")).run();

JRuby

# Create a Manifest object m = Java::JavaUtilJar::Manifest.new attribs = m.mainAttributes # This attribute must be set! See the Manifest Javadocs. attribs.put( Java::JavaUtilJar::Attributes::Name::MANIFEST_VERSION, "1.0") # Add information on the build date attribs.put( Java::JavaUtilJar::Attributes::Name.new("Build-date"), Java::JavaText::SimpleDateFormat.new("yyyy.MM.dd").format(Java::JavaUtil::Date.new)) # ... and on the project attribs.put( Java::JavaUtilJar::Attributes::Name.new("Project"), "MyProject") Schmant::JarTF.new. addSource(Schmant::DirectoryAndFilter.new( $d1, Schmant::EFileNameExtensionFilter.new("class"))). setManifest(m). setTarget( Schmant::FutureFile.new($d, "d1-1.0.jar")).run

Jython

from java.util.jar import Manifest, Attributes from java.text import SimpleDateFormat # Create a Manifest object m = Manifest() attribs = m.getMainAttributes() # This attribute must be set! See the Manifest Javadocs. attribs.put( Attributes.Name.MANIFEST_VERSION, \ "1.0") # Add information on the build date attribs.put( Attributes.Name("Build-date"), \ SimpleDateFormat("yyyy.MM.dd").format(Date())) # ... and on the project attribs.put( Attributes.Name("Project"), \ "MyProject") JarTF(). \ addSource(DirectoryAndFilter( d1, \ EFileNameExtensionFilter("class"))). \ setManifest(m). \ setTarget( FutureFile(d, "d1-1.0.jar")).run()

Example 4

Create a Jar archive from the files in the directory hierarchy under d1. Add an entry to the META-INF/services catalog (the example is from the Jar file specification). Put the Jar file in the directory d.

JavaScript

new JarTF(). addSource(d1). addSource( new EntityAndAbsoluteLocation( new NamedReadableFileAdapter( new CharSequenceReadableFile( "sun.io.StandardCodec # Standard codecs for the platform\n"), "CharCodec"), "/META-INF/services")). setTarget( new FutureFile(d, "misc.jar")).run();

Example 5

Create a new Jar file, tutti.jar, containing the data from this.jar, that.jar and everything_else.jar.

Groovy

import org.entityfs.util.Directories; import org.entityfs.zip.ZipFileSystemBuilder; import org.schmant.support.FutureFile; import org.schmant.task.jdk.jar.JarTF // All jar files to merge are in the Directory d. // // Create an EntityFS Zip file system on each Jar file. The Zip file systems // must be closed when we're done with them. def jarFiles = ["this.jar", "that.jar", "everything_else.jar"] // Create the Jar file task def mergeJar = new JarTF(). setTarget(new FutureFile(d, "tutti.jar")) def zipFileSystems = [] try { // Create the Zip file systems and add their root directories to the Jar task zipFileSystems = jarFiles.collect { def zipFileSystem = new ZipFileSystemBuilder(). setZipFile(Directories.getFile(d, it)). create() mergeJar.addSource(zipFileSystem.rootDirectory) return zipFileSystem } // Create the Jar mergeJar.run() } finally { // Close all Zip file systems zipFileSystems.each { it.close() } }

JavaScript

// All jar files to merge are in the Directory d. // // Create an EntityFS Zip file system on each Jar file. The Zip file systems // must be closed when we're done with them. var jarFiles = ["this.jar", "that.jar", "everything_else.jar"]; // Create the Jar file task var mergeJar = new JarTF(). setTarget(new FutureFile(d, "tutti.jar")); var zipFileSystems = []; try { // Create the Zip file systems and add their root directories to the Jar task for (var i = 0; i < jarFiles.length; i++) { // Have to qualify the ZipFileSystemBuilder package name since it is not // imported by default by Schmant. var zipFileSystem = new Packages.org.entityfs.zip.ZipFileSystemBuilder(). setZipFile(Directories.getFile(d, jarFiles[i])). create(); zipFileSystems.push(zipFileSystem); mergeJar.addSource(zipFileSystem.getRootDirectory()); } // Create the Jar mergeJar.run(); } finally { // Close all Zip file systems for (var i = 0; i < zipFileSystems.length; i++) { zipFileSystems[i].close(); } }

JRuby

# All jar files to merge are in the Directory d. # # Create an EntityFS Zip file system on each Jar file. The Zip file systems # must be closed when we're done with them. jarFiles = ['this.jar', 'that.jar', 'everything_else.jar'] # Create the Jar file task mergeJar = Schmant::JarTF.new. setTarget(Schmant::FutureFile.new($d, "tutti.jar")) zipFileSystems = [] begin # Create the Zip file systems and add their root directories to the Jar task zipFileSystems = jarFiles.collect { |jarFile| zipFileSystem = Java::OrgEntityfsZip::ZipFileSystemBuilder.new. setZipFile(Schmant::Directories.getFile($d, jarFile)). create mergeJar.addSource(zipFileSystem.rootDirectory) # Return the file system from the collect block zipFileSystem } # Create the Jar mergeJar.run ensure # Close all Zip file systems zipFileSystems.each { |fs| fs.close } end

Jython

# All jar files to merge are in the Directory d. from org.entityfs.zip import ZipFileSystemBuilder # Create an EntityFS Zip file system on each Jar file. The Zip file systems # must be closed when we're done with them. jarFiles = ["this.jar", "that.jar", "everything_else.jar"] # Create the Jar file task mergeJar = JarTF(). \ setTarget(FutureFile(d, "tutti.jar")) zipFileSystems = [] try: # Create the Zip file systems and add their root directories to the Jar task for jarFile in jarFiles: zipFileSystem = ZipFileSystemBuilder(). \ setZipFile(Directories.getFile(d, jarFile)). \ create() zipFileSystems.append(zipFileSystem) mergeJar.addSource(zipFileSystem.rootDirectory) # Create the Jar mergeJar.run() finally: # Close all Zip file systems def closeZipFileSystem(fs): fs.close() map(closeZipFileSystem, zipFileSystems)


* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.