SRO.CLSJVM.JAR 1.0.1

SRO.CLSJVM.JAR

A multi-platform .NET library for reading, writing, and inspecting Java Archive (JAR) files. Built on top of System.IO.Compression, the library provides a JAR-aware API that handles the META-INF/MANIFEST.MF format, directory entry synthesis, and both file-system and in-memory archive construction — all without a JDK dependency.

Supported Frameworks

Target Framework Status
.NET Framework 4.7.2 Supported
.NET Framework 4.8 Supported
.NET 8 Supported
.NET 9 Supported

Installation

dotnet add package SRO.CLSJVM.JAR

Or via the NuGet Package Manager in Visual Studio — search for SRO.CLSJVM.JAR.

Namespace

using SRO.CLSJVM.JAR;

Quick Start

1 — Inspect an Existing JAR

Open a JAR, read its manifest, and iterate over all entries:

using SRO.CLSJVM.JAR;
using System.IO;

using (FileStream fs = File.OpenRead("myapp.jar"))
{
    JARProcessor processor = new JARProcessor();
    JarSummary summary = processor.JARExtractSummary(fs);

    // Read manifest attributes
    Console.WriteLine("Manifest-Version : " + summary.Manifest.ManifestVersion);
    Console.WriteLine("Created-By       : " + summary.Manifest.CreatedBy);
    Console.WriteLine("Main-Class       : " + summary.Manifest.MainClass);

    // Iterate entries
    foreach (JarEntrySummary entry in summary.Entries)
    {
        Console.WriteLine(entry.JarPath + "  (" + entry.Length + " bytes)");
    }
}

2 — Create a JAR from a Directory

Archive the contents of a directory (excluding the root directory name itself from the JAR paths):

using SRO.CLSJVM.JAR;
using System.IO;

Manifest manifest = new Manifest();
manifest.ManifestVersion = "1.0";
manifest.CreatedBy = "MyBuildTool";
manifest.MainClass = "com.example.Main";

JARProcessor processor = new JARProcessor();

using (FileStream jarOut = File.Create("output.jar"))
{
    processor.JARDirectoryContents(jarOut, new DirectoryInfo(@"C:\build\classes"), manifest);
}

3 — Create a JAR from a File List

When you need fine-grained control over which files are included:

using SRO.CLSJVM.JAR;
using System.Collections.Generic;
using System.IO;

DirectoryInfo root = new DirectoryInfo(@"C:\build\classes");
List<FileInfo> files = new List<FileInfo>
{
    new FileInfo(@"C:\build\classes\com\example\Main.class"),
    new FileInfo(@"C:\build\classes\com\example\Helper.class")
};

Manifest manifest = new Manifest();
manifest.ManifestVersion = "1.0";
manifest.MainClass = "com.example.Main";

JARProcessor processor = new JARProcessor();

using (FileStream jarOut = File.Create("filtered.jar"))
{
    processor.JARFileList(jarOut, root, files, manifest);
}

4 — Create a JAR from In-Memory Blobs

Build a JAR entirely from in-memory data without touching the file system:

using SRO.CLSJVM.JAR;
using System.Collections.Generic;
using System.IO;

// Text file blob
SimpleJarDataBlob textBlob = new SimpleJarDataBlob("Hello from SRO.CLSJVM.JAR");
textBlob.Path = "META-INF/notice.txt";

// Binary blob
SimpleJarDataBlob binaryBlob = new SimpleJarDataBlob(string.Empty);
binaryBlob.Data = File.ReadAllBytes("Main.class");
binaryBlob.Path = "com/example/Main.class";

List<IJarDataBlob> blobs = new List<IJarDataBlob> { textBlob, binaryBlob };

Manifest manifest = new Manifest();
manifest.ManifestVersion = "1.0";
manifest.MainClass = "com.example.Main";

JARProcessor processor = new JARProcessor();

using (MemoryStream ms = new MemoryStream())
{
    processor.JARBlobList(ms, blobs, manifest);
    File.WriteAllBytes("inmemory.jar", ms.ToArray());
}

5 — Read and Re-Save a JAR (Modify Manifest)

Load an existing JAR, update its manifest, and save it to a new stream:

using SRO.CLSJVM.JAR;
using System.IO;

using (FileStream inputFs = File.OpenRead("original.jar"))
using (JarFile jarFile = new JarFile(inputFs))
{
    // Modify manifest attributes
    jarFile.Manifest.MainClass = "com.example.NewMain";
    jarFile.Manifest.ImplementationVersion = "2.0";

    using (FileStream outputFs = File.Create("updated.jar"))
    {
        jarFile.Save(outputFs);
    }
}

API Reference

JARProcessor

The primary entry point for creating and reading JAR archives.

Method Description
JARDirectoryContents(Stream, DirectoryInfo) Archives all files under a directory into a JAR stream using a default manifest.
JARDirectoryContents(Stream, DirectoryInfo, Manifest) Archives all files under a directory into a JAR stream with a supplied manifest.
JARFileList(Stream, DirectoryInfo, List<FileInfo>, Manifest) Archives a specific list of files into a JAR stream; paths are made relative to root.
JARBlobList(Stream, List<IJarDataBlob>, Manifest) Archives a list of in-memory data blobs into a JAR stream.
JARExtractSummary(Stream) Opens a JAR stream and returns a JarSummary for inspection.

JarFile : IDisposable

Low-level wrapper around a ZipArchive opened in read or create mode. Use using to ensure timely disposal.

Member Description
JarFile(string filepath) Opens a JAR from a file path.
JarFile(FileStream fs) Opens a JAR from a FileStream.
JarFile(Stream s) Opens a JAR from any readable Stream.
Load(Stream) Replaces the currently loaded archive with the one in the given stream.
Save(Stream) Writes the (possibly modified) archive to an output stream.
Save(Stream, DirectoryInfo, List<FileInfo>) Creates a new JAR from a file list relative to a root directory.
Save(Stream, List<IJarDataBlob>) Creates a new JAR from in-memory blobs.
GetInputStream(JarEntry) Returns a readable Stream for a specific entry's data.
GetManifestString() Returns the manifest content as a formatted string.
JarFiles List<JarEntry> — all non-manifest entries; synthetic directory entries are generated when missing.
Manifest The Manifest instance for this archive.

Manifest

Represents META-INF/MANIFEST.MF. All standard JAR manifest attributes are exposed as typed properties.

Property Manifest Attribute
ManifestVersion Manifest-Version
ClassPath Class-Path
CreatedBy Created-By
SignatureVersion Signature-Version
MainClass Main-Class
ImplementationTitle Implementation-Title
ImplementationVersion Implementation-Version
ImplementationVendor Implementation-Vendor
SpecificationTitle Specification-Title
SpecificationVersion Specification-Version
SpecificationVendor Specification-Vendor
AutomaticModuleName Automatic-Module-Name
Sealed Sealed (bool)
MultiRelease Multi-Release (bool)
ManifestLookup Raw Dictionary of all attributes.

Write(ZipArchive) writes the META-INF/ directory entry and META-INF/MANIFEST.MF to an open archive. Call this before writing any other entries.


JarSummary

Returned by JARProcessor.JARExtractSummary. Provides read access to the manifest and all entries.

Property Description
Manifest The Manifest instance parsed from the archive.
Entries List<JarEntrySummary> — one summary per non-manifest entry.

JarEntrySummary

Wraps a JarEntry and its parent JarFile to provide convenient data-access properties.

Property Description
JarPath JAR-relative path for the entry (e.g., com/example/Main.class).
Length Entry data size as int.
LongLength Entry data size as long.
DataStream A readable Stream for the entry binary data.
BinaryContents The entire entry data as a byte[]. Suitable for class files and small resources.
JarEntry The underlying JarEntry.
JarFile The parent JarFile.

JarEntry

Represents a single file or directory entry inside a JAR.

Member Description
Name Full JAR-relative path (e.g., com/example/Main.class or com/example/).
Size Uncompressed size in bytes.
DateTime Last-modification timestamp.
IsDirectory true when Name ends with /.
Real The underlying ZipArchiveEntry; null for synthetically generated directory entries.
CleanName(string) Static helper — replaces backslashes with forward slashes for JAR path normalization.

IJarDataBlob / SimpleJarDataBlob

IJarDataBlob is an interface for supplying in-memory content to JARBlobList / JarFile.Save(Stream, List<IJarDataBlob>).

Member Description
Data Raw binary content as byte[].
Path Forward-slash JAR path for the entry (e.g., resources/icon.png).
Size Length of Data as long.

SimpleJarDataBlob is a convenience implementation. Its string constructor converts text to a UTF-8 byte array automatically.


Notes

  • JAR files are ZIP archives with a required META-INF/MANIFEST.MF. This library always writes the manifest as the first entry to comply with the JAR specification.
  • All JarFile operations that accept a Stream leave the stream open (leaveOpen: true); the caller controls stream lifetime.
  • When opening a JAR that contains no explicit directory entries, JarFile.JarFiles automatically synthesizes JarEntry instances for each implied directory.
  • Path normalization (JarEntry.CleanName) replaces Windows backslashes with forward slashes to keep archive paths portable.

Copyright 2011-2026 Serengeti Research Organization. All rights reserved.

Showing the top 20 packages that depend on SRO.CLSJVM.JAR.

Packages Downloads
SRO.CLSJVM.RefResolution
This multi-platform API provides provides facilities for looking up code entities (reference resolution) such as classes, methods, fields etc for the JVM platform. It is specifically designed to find these entities from compiled data sources such as JARs and directory structures and in the future JIMAGE modules file, as well as gathered source information from early stages of source code building.
7
SRO.CLSJVM.RefResolution
This multi-platform API provides provides facilities for looking up code entities (reference resolution) such as classes, methods, fields etc for the JVM platform. It is specifically designed to find these entities from compiled data sources such as JARs and directory structures and in the future JIMAGE modules file, as well as gathered source information from early stages of source code building.
6
SRO.CLSJVM.RefResolution
This multi-platform API provides provides facilities for looking up code entities (reference resolution) such as classes, methods, fields etc for the JVM platform. It is specifically designed to find these entities from compiled data sources such as JARs and directory structures and in the future JIMAGE modules file, as well as gathered source information from early stages of source code building.
5
SRO.CLSJVM.RefResolution
This multi-platform API provides provides facilities for looking up code entities (reference resolution) such as classes, methods, fields etc for the JVM platform. It is specifically designed to find these entities from compiled data sources such as JARs and directory structures and in the future JIMAGE modules file, as well as gathered source information from early stages of source code building.
4

.NET Framework 4.7.2

  • No dependencies.

.NET Framework 4.8

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

.NET Standard 2.0

  • No dependencies.

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
1.0.1 11 09/02/2026