Git Product home page Git Product logo

jnet's Introduction

JNet: Java/JVM suite for .NET

JNet is a comprehensive suite of libraries and tools to use Java/JVM APIs (Java, Scala, Kotlin, ...) and .NET side-by-side.

Libraries and Tools

JNet JNet.Templates JNetPSCore JNetCLI JNetReflector JNetPS
JNet nuget
downloads
JNet.Templates nuget
downloads
JNetPSCore nuget
downloads
JNetCLI nuget
downloads
JNetReflector nuget
downloads
JNetPS

Pipelines

CI_BUILD CodeQL CI_RELEASE

Project disclaimer

JNet is a suite, curated by MASES Group, can be supported by the open-source community.

Its primary scope is to support other, public or internal, MASES Group projects: open-source community and commercial entities can use it for their needs and support this project, moreover there are dedicated community and commercial subscription plans.

The repository code and releases may contain bugs, the release cycle depends from critical discovered issues and/or enhancement requested from this or other projects.

Looking for the help of experts? MASES Group can help you design, build, deploy, and manage applications mixing .NET and JVM enabled languages.


Scope of the project

This project aims to create a set of libraries and tools to direct access, from .NET, all the features available in the Java Platform, this is the counterpart of JCOReflector.

There are many client libraries written to manage communication with Java. Conversely, this project use directly the Java packages giving more than one benefit:

  • all implemented features are availables at no extra implementation costs, see JNet usage;
  • avoids any third party communication protocol implementation;
  • access all features made available from Java platform.

So, for example, do you want an ArrayList? Just write in C# a line of code like this:

Java.Util.ArrayList<string> alist = new Java.Util.ArrayList<string>();

See JNet usage for a comprehensive example.

Community and Contribution

Do you like the project?

Do you want to help us?

  • put a ⭐ on this project
  • open issues to request features or report bugs 🐛
  • improves the project with Pull Requests

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

Summary

News

  • V1.4.8+: From version 1.4.8 there is a new project, named JNetReflector (still in development phase), able to build C# gateway classes from JARs containing the JVM classes, exactly the same JCOReflector does for .NET in JVM.
  • V1.4.9+: From version 1.4.9 there are two new projects:
    • JNetPSCore: the core library for PowerShell development, it can be extended in other projects based on JNet;
    • JNetPS: a PowerShell module to use JNet within a PowerShell shell.
  • V1.5.2+: strong improvement of JNetReflector; it is used to generate almost all Java 11 classes available in the corresponding JNet version
  • V1.5.3+: JNetReflector manages generics and almost all classes of Java SE 11 are covered: see JNet Reflector usage
  • V2.0.0+: the most notable changes in this version are in:
    • JNet: complete review of all classes based on automatic generation done using JNetReflector
    • JNetReflector: improvements in many areas from generation of .NET interfaces to generics and where clauses, full story in #178
  • V2.3.0+: the most notable changes in this version are in:
    • JNet: review of classes based on latest updates of JNetReflector
    • JNetReflector: use Java.Lang.String, by default, instead of string (System.String) (see #363)
  • V2.4.0+: the most notable changes in this version are in:
    • JNet: review of classes based on latest updates of JNetReflector
    • JNetReflector: use native types only when JVM counter-part is a native type (see #371)
    • JNetReflector: can use signature to invoke JVM methods (see #374) or fallback to current behavior

Runtime engine

JNet uses JCOBridge, and its features, to obtain many benefits:

  • Cyber-security:
    • JVM and CLR, or CoreCLR, runs in the same process, but are insulated from each other;
    • JCOBridge does not make any code injection into JVM;
    • JCOBridge does not use any other communication mechanism than JNI;
    • .NET (CLR) inherently inherits the cyber-security levels of running JVM;
  • Direct access the JVM from any .NET application:
    • Any Java/Scala/Kotlin/... class can be directly managed;
    • No need to learn new APIs: we try to expose the same APIs in C# style;
    • No extra validation cycle on protocol and functionality: bug fix, improvements, new features are immediately available;
    • Documentation is shared;
  • Dynamic code: it helps to write a Java/Scala/Kotlin/etc seamless language code directly inside a standard .NET application written in C#/VB.NET: look at this simple example and JNet APIs extensibility.

JCOBridge resources

Have a look at the following JCOBridge resources:

jnet's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar masesdevelopers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jnet's Issues

It is useful to add cmdlets related to the types implementing NotificationFilter

Class inheritance leads to some exceptions reporting missing methods

Describe the bug
Some static methods of inherited classes report exceptions signalling missing method

To Reproduce
Steps to reproduce the behavior:

  1. Invoke JFrame.SetDefaultLookAndFeelDecorated(true);
  2. Run the code
  3. See error

Expected behavior
The method must be found because it is available is Java

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Version: latest
  • Java: Temurin JDK 11.0.18-10

Additional context
N/A

JNet shall introduce a PowerShell module

Is your feature request related to a problem? Please describe.
PowerShell is a great tool and seems there is no integration with Java.

Describe the solution you'd like
Create a module/snapin, based on JNet, to interact with Java from PoweShell and publish it to PowerShell Gallery. Maybe its name is JNetPS.

See https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/writing-portable-modules?view=powershell-7.2 for further information.

The list of CmdLet to be created will be defined later.

Describe alternatives you've considered
N/A

Additional context
See #49

Create the classes of Listener/Adapter and so on

So in first instance if a class name ends with Listener the tool can avoid its reflection, but in general a tool like JNetReflector cannot distinguish which interface, or class, shall be managed in different way only because it represents a callback.

The previous will be implemented checking if the class name ends with Listener or Adapter, and will be added a command line switch ClassesToBeListener to list all classes which are events callback and be treated as a Listener. Anyway the implementation, till now, shall be done manually.

Remember to create the classes: now they are reported, during compilation, as a warning. The possible options are:

  • create the classes manually
  • find a way to build them automatically following a generation pattern

Originally posted by @masesdevelopers in #130 (comment)

Add reflection tool

Is your feature request related to a problem? Please describe.
To write base classes it is tedious. A tool to reflect classes from Java can be useful.

Describe the solution you'd like
Write a tool able to create classes reading the JARs.
At least, for each JAR and package, can be useful to:

  • for each package create a folder structure corresponding to the package name
  • have an auto-generated file with all partial classes defining the class
  • create many files named like the class that can extend the base class

Describe alternatives you've considered
N/A

Additional context
Something like the tool available in JCOReflector

PutConstraint in Java Swing SpringLayout reports NullPointerException

Describe the bug
When the method PutConstraint is invoked, JCOBridge reports back a NullPointerException. Anyway, attaching with a Java Debugger, no exception (handled or unhandled) is reported from the tool.

To Reproduce
Steps to reproduce the behavior:

  1. Open JNetTests solution
  2. Run JNetWPFTest
  3. Wait the point where PutConstraint is invoked
  4. The code enter in the catch clause

Expected behavior
The code must continue execution without problems.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Version: latest
  • Java: Temurin JDK 11.0.18-10

Additional context
Create the same code in Java and check the behaviour.

KNet needs some classes from JNet

Converts constructor like ClassName(params object[] args) into a protected constructor

Is your feature request related to a problem? Please describe.
Constructor defined like ClassName(params object[] args) are public, anyway they are used only in derived classes; it is better to define them protected to avoid a misuse outside the class that needs it

Describe the solution you'd like
Modify the keyword from public to protected on constructor like ClassName(params object[] args)

Describe alternatives you've considered
N/A

Additional context
N/A

Previous manually made classes shall be updated

Describe the bug
The classes were previously made manually now are, in some case, affected by a wrong set of data like IsAbstract, IsInterface and so on.

To Reproduce
Steps to reproduce the behavior:

  1. Open the test solution
  2. Run JNetTest
  3. Map reports Instance is null
  4. See error

Expected behavior
The classes which now are partially made by the one reflected shall define the definition property in the right way

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: N/A
  • Version: latest commit

Additional context
N/A

Add container for JNet

Is your feature request related to a problem? Please describe.
Other projects are based on JNet. JNet can be available in a container too to be better usable

Describe the solution you'd like
Create a specific Dockerfile and updates workflows to generate and upload the container, specifically during the release phase.

Describe alternatives you've considered
N/A

Additional context
N/A

JNet shall be always aligned to latest JCOBridge release

Is your feature request related to a problem? Please describe.
Update JNet each time JCOBridge updates

Describe the solution you'd like
To be always aligned to latest JCOBridge version and features, @masesdevelopers must update source code and the references to last JCOBridge release.

Describe alternatives you've considered
N/A

Additional context
N/A

Use JNetReflector to create as many classes as possible in JNet

Is your feature request related to a problem? Please describe.
Java has many classes not reflected till now. JNetReflector seems enough mature and it is possible to use it to create gateway classes starting from the JARs of a generic JRE.

Describe the solution you'd like
Within the lib folder of a JRE there are the JARs of the Java SE classes, the main one is rt.jar. Within it there are the .class files usable to create the proxies, many classes are just available.
Since rt.jar is loaded from the JRE itself, it is not possible to add it in the Classpath like JNetReflector does now. So:

  • add an option to avoid to insert the JARs in classpath, but leave them to be analyzed
  • create a specific folder under JNet project to avoid to overwrite available files
  • until now JNetReflector does not manage generation of classes to receive events, verify how to avoid to create standard gateway classes for events

About classes to be reflected: many namespace in rt.jar maybe are internal, after first test try to avoid usefulness namespaces.

Use, as reference, a Java 8 JRE for backward compatibility (the classes available till now was generated from that reference) and use the official Oracle Javadoc URL.

Describe alternatives you've considered
N/A

Additional context
N/A

Use IAsyncEnumerable to perform operation on classes implementing java.lang.Iterable

Is your feature request related to a problem? Please describe.
Since the operation to retrieve the next object from an java.lang.Iterable is time consuming, if it is done inline it reduces the performances of the operation itself.

Describe the solution you'd like
.NET 3 and above contains a new interface named IAsyncEnumerable which is able to do the job requested. For .NET 461+ it is available a NuGet package named Microsoft.Bcl.AsyncInterfaces which exposes this interface to this framework.

Describe alternatives you've considered
Create, in JCOBridge, an alternative class to JVMBridgeBaseEnumerable, or extend the existing one, in order to anticipate the request for next item while the Current is available for consuming.

Additional context
Add generation of related code with JNetReflector

Add conversion API between .NET style and JVM style

Is your feature request related to a problem? Please describe.
There is no conversion API of some kind of objects between .NET and JVM. Examples are:

  • IList <-> Set
  • IEnumerable <-> Iterable
  • IDictionary <->Map
  • and so on

Describe the solution you'd like
Create some helpers to convert the objects between both world

Describe alternatives you've considered
N/A

Additional context
N/A

Add JMX management

Is your feature request related to a problem? Please describe.
Any JVM is able to expose information using JMX specifications. JNet does not implement classes related to JMX.

Describe the solution you'd like
Add some, or all, classes related to JMX so from .NET it is possible to interact with JMX.

Describe alternatives you've considered
N/A

Additional context
N/A

Some operators does not cast to the right destination type

Other than this, some operators will be added to enabled class conversion in case of interfaces, and the format will be:

public static implicit operator DestinationType(OriginType t) => t.Cast<DestinationType>();

Originally posted by @masesdevelopers in #130 (comment)

Previous definition is correct, anyway Cast function does not work in every condition, an enhancement to JCOBridge is necessary

Move JARs under jars folder

Is your feature request related to a problem? Please describe.
The project puts output JARs under main folder, the JARs related to this project shall be placed within a subfolder named jars. So derived projects puts its own JARs within a unique identifiable folder.

Describe the solution you'd like
Update projects and workflows to obtain the result requested.

Describe alternatives you've considered
N/A

Additional context
masesgroup/KNnet use this behavior

Write some kind of generics in a better way

Looking into the code generated it is possible to highlight this:

public bool RemoveAll<Arg0Extendsobject>(Java.Util.Collection<Arg0Extendsobject> arg0)

the corresponding Java code is:

boolean removeAll​(Collection<?> c)

surely the above C# code works, anyway for native types like long there is something like this:

public void ForEachRemaining<Arg0objectSuperlong>(Java.Util.Function.Consumer<Arg0objectSuperlong> arg0)

the Java code is:

void forEachRemaining​(Consumer<? super Long> action)

but in C# a long is sealed so we can remove the generic otherwise there isn't a right constraint in the code.

Originally posted by @mariomastrodicasa in #145 (comment)

DoxFX is unable to create documentation

Describe the bug
The documentation is not generated

To Reproduce
Steps to reproduce the behavior:

  1. Run the build.yaml
  2. Go to Build documentation step
  3. Find the [Failure] Msbuild failed when processing the file 'D:\a\JNet\JNet\src\net\JNet\JNet.csproj' with message: Method not found: 'System.ReadOnlySpan1<Char> Microsoft.IO.Path.GetFileName(System.ReadOnlySpan1)'.

Expected behavior
The documentation shall be generated

Screenshots
image

Desktop (please complete the following information):

  • OS: GitHub Virtual environment
  • Image Version: 20220816.1

Additional context
Seems the error is well known because it is an open issue of DocFX: dotnet/docfx#8097

Poor JNetPS online description

Describe the bug
The documentation of JNetPS is poor.

To Reproduce
N/A

Expected behavior
Add more info to give users a better understanding.

Screenshots
image

Desktop (please complete the following information):

  • OS: All
  • Version 1.4.11

Additional context
Related to #50

Remove .NET Core 3.1 and add .NET 7

Is your feature request related to a problem? Please describe.
.NET Core 3.1 reach End of Support in December, while it is available latest .NET 7 version

Describe the solution you'd like
Upgrade the projects

Describe alternatives you've considered
N/A

Additional context
Must wait upcoming release of JCOBridge

Invoking methods with a single array parameter reports a missing method exception

Describe the bug
Invoking methods with a single parameter whose type is an array reports a missing method exception.

To Reproduce
Steps to reproduce the behavior:

  1. Invoke
    public void AddRow(object[] arg0)
  2. See error

Expected behavior
The method shall be invoked without problems

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: All
  • Version: latest JNet
  • Java: Temurin JDK 11.0.18-10

Additional context
N/A

Make public the command-line arguments properties

Is your feature request related to a problem? Please describe.
Argument properties ( CommandLineArguments and ParsedArgs) shall be made public to use them outside initialization of JNetCore

Describe the solution you'd like
Change visibility of the properties from protected to public

Describe alternatives you've considered
N/A

Additional context
N/A

Change node from version 12 to version 16

Describe the bug
There is a warning during build:
The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

To Reproduce
Steps to reproduce the behavior:

  1. See output of GitHub workflow

Expected behavior
Remove warning

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: ALL
  • Version: latest workflow images

Additional context
Add any other context about the problem here.

Verify why an ArrayList reports value as HashMap$Node as results of iteration

The following line of code

var list = ((Collection<string>)alist).ToList(); // Raise an exception because iterator returns java/util/HashMap$Node which is not convertible to string

fails with an exception from JCOBridge because the data type returned from the iterator is an internal type (java.util.HashMap$Node) and not the original type which is string(java.lang.String).

Centralize better versioning

Is your feature request related to a problem? Please describe.
Update version is a error prone task. Find a way to update version using a single point

Describe the solution you'd like
For some projects the version is written in Common.props, but:

  • Java side: POM.xml has version within the XML; if version depends on an user property it is possible to set it via command-line
  • JNetPS: the version shall be changed in multiple file, maybe a script (PowerShell) can update it reading the actual version from Common.props

Describe alternatives you've considered
N/A

Additional context
N/A

JNetCLI shall become a REPL tool

Is your feature request related to a problem? Please describe.
There is no CLI to interact with JNet. The JNetCLI tool can be used to run Java classes or execute code.

Describe the solution you'd like
The JNetCLI shall work in, at least, two different ways:

  • Interactive mode: the user launches the program and a REPL interface will be available; inserting code an user can request JVM objects and interact, side-by-side, with .NET objects;
  • Run mode: the user requests to launch a JVM class (the one with a main) with arguments in command-line; this is the same behavior of java command-line executable.

An extra mode to be considered is:

  • Script mode: the user requests to launch a C# Script (mix of .NET and JVM objects) which executes and then exit.

Describe alternatives you've considered
N/A

Additional context
N/A

Update documentation to better describe the usage

On *nix systems: JCOBridge try to find an incorrect library name and location if JAVA_HOME points out to the JRE folder, this is an open issue. The common way of work is to use the command-line switch JVMPath. JCOBridge has multiple command-line switches and one of them is dedicated to set the JVM library location. Use JVMPath in any shell (Windows, bash, etc) to set-up the JVM library location:

--JVMPath:<full-path-to jvm.dll or libjvm.so>

other options under https://www.jcobridge.com/net-examples/command-line-options/.

If the developer/user cannot use the command-line switch, another way to overcome this behavior is to override the property JVMPath with a snippet like the following:

    class MyKNetCore : KNetCore
    {
        public override string JVMPath
        {
            get
            {
                string pathToJVM = "Set here the path to JVM library or use your own search method";
                return pathToJVM;
            }
        }
    }

#110 will cover an enhancement about usage and environment set-up.

Originally posted by @masesdevelopers in masesgroup/KNet#115 (comment)

Generated documentation can be improved

Looking into the generated documentation seems that:

  • Operators miss references to the classes used: an help like Converter from X to Y, where X and Y are the links to the documentation
  • Method help does not report the parameter, return and exception which can be retrieved as reference and inserted into documentation: adding the references within these fields better fills the empty fields in documentation; maybe this can be done only for non native types

Originally posted by @mariomastrodicasa in #130 (comment)

Remove .NET 5 due to its End of Support

Is your feature request related to a problem? Please describe.
.NET reached End of Support on 10 May 2022

Describe the solution you'd like
Remove .NET 5 target runtime

Describe alternatives you've considered
N/A

Additional context
N/A

Strongly reference JNet jar

Is your feature request related to a problem? Please describe.
If in the deployment folder there are multiple version of jnet-*.jar the last version is not choosen because the operating system reports the versions in lexicographically order and the oldest one is the first and choosen.

Describe the solution you'd like
Strongly set the version during jars import clause in this line:

lst.Add(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(JNetCore).Assembly.Location), JARsSubFolder, "*.jar"));

using the version defined on the assembly executing the code. JAR and assembly is expected have the same version.

Describe alternatives you've considered
Set the version each time the version change.

Additional context
N/A

Templates are unuseful

The templates package contains only a single project and its code is very simple. Update the actual one with a more useful code, e.g. comment it. Add more templates which covers multiple usage context of the library.

Updates variadic method execution

The solution identified is to verify if any parameter is passed to the variadic argument and execute different codes: if no variadic arguments are available, the underlying method avoids the variadic argument. A proposal for the method reported in the issue is:

        public Topology AddSource(string name, params string[] topics)
        {
            return topics.Length == 0 ? IExecute<Topology>("addSource", name)
                                      : IExecute<Topology>("addSource", name, topics);
        }

The modification will be applied on next release when JCOBridge 2.5.0 will be available. An issue will be opened in masesgroup/JNet to cover similar problems.

Originally posted by @masesdevelopers in masesgroup/KNet#160 (comment)

Copy action within project shall be contextualized to avoid problems in inheritance of multiple *.targets file.

    Copy action within project shall be contextualized to avoid problems in inheritance of multiple *.targets file. Here the snippet which solves the problem:
	<ItemGroup Condition="True">
		<jnetps_jars Include="$(ProjectDir)\..\..\..\jars\*.*" />
		<jnetps_config Include="$(ProjectDir)\..\..\config\*.*" />
		<jnetps_kraft Include="$(ProjectDir)\..\..\config\kraft\*.*" />
	</ItemGroup>

	<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
		<Copy SourceFiles="@(jnetps_jars)" DestinationFolder="$(OutDir)\jars" />
		<Copy SourceFiles="@(jnetps_config)" DestinationFolder="$(OutDir)\config" />
		<Copy SourceFiles="@(jnetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
	</Target>
	<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
		<Copy SourceFiles="@(jnetps_jars)" DestinationFolder="$(OutDir)\jars" />
		<Copy SourceFiles="@(jnetps_config)" DestinationFolder="$(OutDir)\config" />
		<Copy SourceFiles="@(jnetps_kraft)" DestinationFolder="$(OutDir)\config\kraft" />
	</Target>

Originally posted by @masesdevelopers in masesgroup/KNet#100 (comment)

Avoid filtering of generic types

Other than this, some operators will be added to enabled class conversion in case of interfaces, and the format will be:

@masesdevelopers looking in the code and in the Java 11 documentation it is possible to highlight some missing operators. An example is BlockingQueue which miss all operators.

Seems the filtering happens in:

if (implementedInterface.IsOrInheritFromJVMGenericClass())

which filters generic types, however generic classes are no more filtered.
The same filter is applied in:
if (parameter.Type.IsOrInheritFromJVMGenericClass()) { bypass = true; break; }

and
if (method.ReturnType.IsOrInheritFromJVMGenericClass())

and
if (parameter.Type.IsOrInheritFromJVMGenericClass()) { bypass = true; break; }

Originally posted by @mariomastrodicasa in #130 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.