MASES.JNet 1.5.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MASES.JNet --version 1.5.3
NuGet\Install-Package MASES.JNet -Version 1.5.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MASES.JNet" Version="1.5.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MASES.JNet --version 1.5.3
#r "nuget: MASES.JNet, 1.5.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MASES.JNet as a Cake Addin
#addin nuget:?package=MASES.JNet&version=1.5.3

// Install MASES.JNet as a Cake Tool
#tool nuget:?package=MASES.JNet&version=1.5.3

JNet usage

To use JNet classes the developer can write code in .NET using the same classes available in the official Java packages. If classes or methods are not available yet it is possible to use the approach synthetized in What to do if an API was not yet implemented

Basic example

Below a basic example which demonstrates how to create a program based on JNet and some other features available like generics and exception handling. Within the program the comments try to explain how the code works.

using Java.Util;
using MASES.JNet.Extensions;
using System.Diagnostics;
using Java.Lang;

namespace MASES.JNetExample
{
    // this class defines a concrete implementation of JNetCore<>
    class MyJNetCore : JNetCore<MyJNetCore>
    { 
    }

    class Program
    {
        static void Main(string[] args)
        {
            // the first step is mandatory: 
            // it invokes the method CreateGlobalInstance to allocate the JVM and prepares the environment
            MyJNetCore.CreateGlobalInstance();
            // at the end of initialization the arguments in the command line not used from JNet (and JCOBridge) 
            // are available to be used like any developer does with the args in the Main 
            var appArgs = MyJNetCore.FilteredArgs;

            // now we go into .NET/JVM interaction based on generics
            try
            {
                // in the first step the code allocates a java.util.Set<String> within the JVM using the java.util.Collections class
                // and returns a Java.Util.Set<string> in .NET
                var set = Collections.Singleton("test");
                // then the code tries to Add a new value if it is available in command-line, 
                // but we expect the JVM raises an exception
                if (appArgs.Length != 0) set.Add(appArgs[0]);
            }
            // if the Add is invoked the operation on java.util.Set<String> cannot be performed 
            // because Collections.Singleton returns an immutable java.util.Set<String>
            // see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#singleton(T))
            catch (UnsupportedOperationException) 
            {
                // so we enter here because the engine translates the Java exception in an equivalent exception managed from C#
                System.Console.WriteLine("Operation not supported as expected");
            }
            // this piece of code is for any convenience because we want a clean close of the application
            catch (System.Exception ex) { System.Console.WriteLine(ex.Message); }
        }
    }
}

Environment setup

JNet accepts many command-line switches to customize its behavior. The full list is available at Command line switch page.

JVM identification

One of the most important command-line switch is JVMPath and it is available in JCOBridge switches: it can be used to set-up the location of the JVM library (jvm.dll/libjvm.so) if JCOBridge is not able to identify a suitable JRE installation. If a developer is using JNet within its own product it is possible to override the JVMPath property with a snippet like the following one:

    class MyJNetCore : JNetCore
    {
        public override string JVMPath
        {
            get
            {
                string pathToJVM = "Set here the path to JVM library or use your own search method";
                return pathToJVM;
            }
        }
    }
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MASES.JNet:

Package Downloads
MASES.KNet

Core of .NET suite for Apache Kafka. KNet is a comprehensive .NET suite for Apache Kafka providing all features: Producer, Consumer, Admin, Streams, Connect, backends (ZooKeeper and Kafka).

MASES.JNetPSCore

JNetPSCore - JNet (Java/JVM suite for .NET) PowerShell base library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.4.0 80,341 2/29/2024
2.3.0 923 2/20/2024
2.2.5 58,768 1/30/2024
2.2.4 48,426 1/27/2024
2.2.3 1,758 1/24/2024
2.2.2 1,211 1/24/2024
2.2.1 12,514 1/20/2024
2.2.0 1,512 1/17/2024
2.1.1 1,988 12/18/2023
2.1.0 92,785 11/25/2023
2.0.2 47,529 10/18/2023
2.0.1 194,899 7/11/2023
2.0.0 36,974 7/5/2023
1.5.5 56,610 5/5/2023
1.5.4 45,926 4/16/2023
1.5.3 32,628 4/10/2023
1.5.2 64,881 3/13/2023
1.5.1 55,265 2/9/2023
1.5.0 889 2/8/2023
1.4.15 143,962 11/21/2022
1.4.14 1,342 11/9/2022
1.4.13 981 11/9/2022
1.4.12 19,895 10/30/2022
1.4.11 1,077 10/27/2022
1.4.8 19,543 10/20/2022
1.4.7 1,073 10/13/2022
1.4.6 236,265 8/18/2022
1.4.5 1,087 8/5/2022
1.4.4 1,127 6/19/2022
1.4.3 34,522 5/19/2022
1.4.2 1,354 5/7/2022
1.4.1 1,110 4/29/2022
1.4.0 945 4/13/2022
1.3.0 5,516 3/28/2022
1.2.0 901 3/25/2022
1.1.1 1,309 3/19/2022
1.1.0 865 3/19/2022
1.0.0 898 3/19/2022