当前位置:网站首页>Ikvm of toolbox Net project new progress
Ikvm of toolbox Net project new progress
2022-07-07 13:21:00 【Microsoft technology stack】
One thing that is often discussed in various groups is .NET How to call Java The implementation of the , One of the most common scenarios is in encryption and decryption Java Key provided ,C# Can't decrypt , C# in byte The scope is [0,255], and Java Medium byte The scope is [-128,127], Because the password generator is Java Unique , Other languages do not support (IOS,ANDROID,C#,.NET etc. ), since Java So unique , The solution we used was Java Fan's .
Java and .NET It is the two main technologies of software development at present ,Java 8 Although it is an older technology , A lot of work has been done . therefore , When it comes to reusability , stay .NET Used in Java Libraries created in are a very common practice . Suppose you are already in Java A library has been developed in , And want to be in .NET Use it in projects , that IKVM.NET Help in .NET Use in Java library .
This is the protagonist we are going to introduce today IKVM.NET , IKVM.NET The project has a very long history , As early as 2006 In, I wrote an article on my blog 《 stay .NET Run on the platform Java Program -IKVM.NET introduction 》[1], IKVM.NET and Mono The same is .NET Open source prehistoric community projects ,IKVM It's a Java To .NET The compiler , and Mono yes .NET Framework The open source 、 Cross platform version .2017 year IKVM.NET The author decided to give up IKVM.NET Development of , Since then, some people in the community have diverged IKVM.NET And continue to work , Although the development work is not very active , But in the 2022 year 3 The development has been very active since January (https://github.com/ikvm-revived/ikvm)[2], Now we can fully support .NET 6 了 .
IKVM.NET There are three main components :
stay .NET Implemented in Java virtual machine : It has a use C#.NET Developed JVM, It provides bytecode conversion and verification , Class loading and other functions , The current support Java 8, This is also Java The most used version .
Java The class library .NET Realization : It basically uses OpenJDK[3] Project to achieve JDK library .
Support Java and .NET Interoperability tools :IKVM.NET Include the following tools :
a) ikvm:Java virtual machine : We can relate it to java.exe(“ Dynamic mode ”) Compare . It loads a class file and executes its main Method , If we pass the class file name as a parameter , Then it will be executable jar In the document Java Code . If we put a jar File is passed as a parameter , Then it will execute it .
b) ikvmc: take Java Bytecode is compiled into CIL, Is used to Java Classes and jar Compiled into .NET Assembly (“ Static mode ”). This tool will Java Bytecode to .NET DLL and exe. It will import... In the file Java Bytecode to .NET DLL. therefore , When we pass multiple jar File and class file , It will combine them and generate a single exe or DLL file . yes exe still DLL Depends on the class file passed and jar Whether the document has Main Method . If they have one Main Method , Then it will generate a exe, otherwise DLL.
c) ikvmstub: from .NET Assembly build Java Stub class : It is from .NET Assembly generates stub class files , So that we can aim at .NET The code to compile Java Code .ikvmstub Tools from .NET Assembly build Java stub .ikvmstub Reads the specified assembly and generates a containing Java Interface and stub class Java jar file .
IKVM.NET It is very useful for various software development schemes . Here are some examples of possibilities .
Plug in JVM Included in the distribution IKVM The application is Java The virtual machine .NET Realization . in many instances , You can use it as Java A direct alternative to . for example , No typing required “java -jar myapp.jar” To run the application , You can type :ikvm -jar myapp.jar
stay .NET Used in applications Java library ,IKVM.NET Include ikvmc, One Java Bytecode to .NET IL converter . If you have one Java library , You want to .NET Used in applications , And then run “ikvmc -target:library mylib.jar” To create “mylib.dll”. for example ,Apache FOP The project is a project with Java Write open source XSL-FO processor , Widely used from XML Source generation PDF file . With the help of IKVM.NET technology ,Apache FOP Can be used by any .NET Application usage .
use Java Development .NET Applications IKVM It provides you with a Java Development .NET The method of application . although IKVM.NET Excluding for .NET Of Java compiler , But you can use any Java Compiler will Java Source code compiled as JVM Bytecode , And then use “ikvmc -target:exe myapp.jar” To generate .NET Executable file . You can even use the included ikvmstub The application is Java The code uses .NET API.
▌ Support platform
.NET Framework 4.6.1 And higher
.NET Core 3.1 And higher
.NET 5 And higher
Java SE 8
▌IkvmReference
IKVM Include support for generating Java The library is converted to .NET Assembly , This is a recently added feature , For details, please refer to IkvmReference design scheme [4]. To quote Java Install the package in the project of the library . Use IkvmReference
To indicate what your project needs Java library .
example :
<ItemGroup>
<IkvmReference Include="..\..\ext\helloworld-2.0.jar" />
</ItemGroup>
The output assembly will be generated as part of the project build process . Can be directed to IkvmReference
Additional metadata is added to customize the generated assembly .
Identity
: The identification of the project can be a) JAR Path to file b) The path to the directory or c) Other unimportant names .IkvmReference
AssemblyName
: By default , Use the rules defined by the specification to generate . To overwrite this , Please do this here .AssemblyName
Automatic-Module-Name
AssemblyVersion
: By default , Use the rules defined by the specification to generate . To overwrite this , Please do this here .AssemblyVersion
Automatic-Module-Name
DisableAutoAssemblyName
: If you disable testing .true
AssemblyName
DisableAutoAssemblyVersion
: If you disable testing .true
AssemblyVersion
FallbackAssemblyName
: If not provided or cannot be calculated , Please use this value .AssemblyName
FallbackAssemblyVersion
: If not provided or cannot be calculated , Please use this value .AssemblyVersion
Compile
: Optional semicolon delimited Java List of classpath items , To compile into an assembly . By default , If the identification of the project is existing JAR File or directory ( Not yet supported ), Then this value is the value of the item . Support MSBuild Client references multiple JAR or .class file .Identity
Sources
: To be used during document generation Java Optional semicolon delimited list of source files .( Not yet in favor of )
References
: Optional semicolon separated list of other identification values , To specify as a reference to the current identity value . for example , Depend on if , Then include both as items , But in Metadata specifies The logo of .IkvmReference
foo.jar
bar.jar
IkvmReference
bar.jar
References
foo.jar
Debug
: Indicates whether debug symbols are generated ( It's not portable ) Optional Boolean value of . By default , This is determined according to the overall setting of the project .
MSBuild All other metadata supported by item group definitions .
Reference
IkvmReference
Not transferable . Including it in one project and adding a dependency to that project from the second project does not result in the same reference being provided on the second project . Instead, add a reference to each project .
For each project to resolve to the same generated assembly , Make sure that the settings are the same .
<ItemGroup>
<IkvmReference Include="helloworld.jar">
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</IkvmReference>
<IkvmReference Include="helloworld-2.jar">
<AssemblyName>helloworld-2</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<References>helloworld.jar</References>
<Aliases>helloworld2</Aliases>
</IkvmReference>
</ItemGroup>
Related links :
[1] stay .NET Run on the platform Java Program -IKVM.NET introduction :
https://www.cnblogs.com/shanyou/articles/343118.html
[2] ikvm Github Resurrection warehouse :
https://github.com/ikvm-revived/ikvm
[3] OpenJDK:
http://openjdk.java.net/
[4] IkvmReference design scheme :
https://github.com/ikvm-revived/ikvm/issues/54
Focus on Microsoft China MSDN Learn more about
Click to go to .NET Chinese official website ~
边栏推荐
- 日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
- OSI 七层模型
- php——laravel缓存cache
- RealBasicVSR测试图片、视频
- PACP学习笔记一:使用 PCAP 编程
- Blog recommendation | Apache pulsar cross regional replication scheme selection practice
- Cloud detection 2020: self attention generation countermeasure network for cloud detection in high-resolution remote sensing images
- Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
- File operation command
- Practical example of propeller easydl: automatic scratch recognition of industrial parts
猜你喜欢
error LNK2019: 无法解析的外部符号
【无标题】
飞桨EasyDL实操范例:工业零件划痕自动识别
Digital IC Design SPI
【学习笔记】zkw 线段树
存储过程的介绍与基本使用
Star Enterprise Purdue technology layoffs: Tencent Sequoia was a shareholder who raised more than 1billion
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
基于鲲鹏原生安全,打造安全可信的计算平台
cmake 学习使用笔记(一)
随机推荐
日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
单片机学习笔记之点亮led 灯
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
Mongodb slice summary
【Presto Profile系列】Timeline使用
[learning notes] zkw segment tree
QQ medicine, Tencent ticket
Scripy tutorial classic practice [New Concept English]
PACP学习笔记三:PCAP方法说明
DETR介绍
Enterprise custom form engine solution (XII) -- experience code directory structure
. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst
学习突围2 - 关于高效学习的方法
DrawerLayout禁止侧滑显示
[untitled]
QQ的药,腾讯的票
Aosikang biological sprint scientific innovation board of Hillhouse Investment: annual revenue of 450million yuan, lost cooperation with kangxinuo
飞桨EasyDL实操范例:工业零件划痕自动识别
How to reset Firefox browser
记一次 .NET 某新能源系统 线程疯涨 分析