Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Português - Русский - 日本語

Please note that the recommended version of Scilab is 6.0.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Java depuis Scilab > jcreatejar


Creates a Java ARchive (JAR) from a set of files / directories

Calling Sequence

jcreatejar(jarFilePath, filePaths[, rootPath[, manifestFilePath]])



A string containing the destination file path of the JAR.


A row / column string matrix containing the paths of the input files/directories to include in the JAR.


An optional string setting the path from which the relative paths in the JAR of all the input files/directories will be computed.


An optional string setting the file path of the manifest data to include in the JAR.


Creates a JAR (Java ARchive) file from a set of input files / directories. A common use is to a create Java packages (which contain Java classes). For example, the function ilib_build_jar uses jcreatejar to build toolboxes containing Java sources. But jcreatejar can also be used to compress files of any type (for example to send them over a network).

Most of times, a JAR file is created from a single tree of files, and the path tree in the JAR file is the same as the input path tree. So when jcreatejar is given a set of files and directories, it automatically computes the root path of all that files / directories, and set the paths in the JAR relative to that root path. This one can also be explicitly specified in the rootPath argument.

A JAR file contains a manifest, which contains data to describe the content of the JAR. In the JAR, this manifest is the file MANIFEST.MF in the META-INF folder. The manifest file can be automatically found at that location in the input tree, or the file path to the manifest can be given in the manifestFilePath argument. If the manifest file cannot be found, a default manifest will be created in the JAR. Note: if a manifest is given, it must contain a version attribute, otherwise the manifest in the JAR will be empty.

The JAR destination file path, stored in the argument jarFilePath, should have the extension .jar. The destination JAR file, if it already exists, is overwritten.


// Example of jcreatejar: create a JAR containing a Java package

// Create a directory for package sources
jar_src_path = fullfile(TMPDIR, 'jarPackageExample');

// Create a Java source and compiles it to a Java class
function createJavaClass(class_name, code)
    class_src_path = fullfile(jar_src_path, class_name + '.java');
    fd = mopen(class_src_path, 'wt');
    mputl(code, fd);

// Create a class in the root of the package
createJavaClass('Class1', msprintf( ..
    'package jarPackageExample;\n' + ..
    'public class Class1 {}'));

// Create another class in a folder of the package
mkdir(fullfile(jar_src_path, 'folder'));
createJavaClass('folder/Class2', msprintf( ..
    'package jarPackageExample.folder;\n' + ..
    'public class Class2 {}'));

// The compiled package is in TMPDIR in JIMS folder
jar_tmp_path = fullfile(TMPDIR, 'JIMS/bin/jarPackageExample');

// Create the package JAR
jar_dest_path = fullfile(TMPDIR, 'jarPackageExample.jar');
jcreatejar(jar_dest_path, jar_tmp_path);
// Example of jcreatejar: create a JAR containing images, and add a manifest

// Create the manifest file
manifest_path = fullfile(TMPDIR, 'MANIFEST.MF');
manifest = msprintf('Manifest-Version: 1.0\nName: Scilab images');
fd = mopen(manifest_path, 'wt');
mputl(manifest, fd);

// Create the JAR
jar_src_path = fullfile(SCI, 'modules/gui/images/icons');
jar_dest_path = fullfile(TMPDIR, 'jarImagesExample.jar');
jcreatejar(jar_dest_path, jar_src_path, '', manifest_path);

See Also


5.5.0 Function introduced.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:54:44 CEST 2014