Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.5.1 - Português

Change language to:
English - Français - 日本語 - Русский

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

Ajuda do Scilab >> Java from Scilab > jcreatejar

jcreatejar

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

Calling Sequence

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

Parameters

jarFilePath

A string containing the destination file path of the JAR.

filePaths

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

rootPath

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

manifestFilePath

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

Description

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.

Examples

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

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

// 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);
    mclose(fd);
    jcompile(class_src_path);
endfunction

// 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);
mclose(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

History

VersãoDescrição
5.5.0 Function introduced.
Report an issue
<< jconvMatrixMethod Java from Scilab jdeff >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:57:52 CEST 2014