当前位置:网站首页>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 ~
边栏推荐
- MongoDB的导入导出、备份恢复总结
- 记一次 .NET 某新能源系统 线程疯涨 分析
- DETR介绍
- Clion mingw64 Chinese garbled code
- 单片机学习笔记之点亮led 灯
- centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
- Initialization script
- Write it down once Net a new energy system thread surge analysis
- Mongodb replication (replica set) summary
- MongoDB的用户管理总结
猜你喜欢
Analysis of DHCP dynamic host setting protocol
分布式事务解决方案
Introduce six open source protocols in detail (instructions for programmers)
Vscade editor esp32 header file wavy line does not jump completely solved
Practical example of propeller easydl: automatic scratch recognition of industrial parts
迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
飞桨EasyDL实操范例:工业零件划痕自动识别
leecode3. 无重复字符的最长子串
[learning notes] zkw segment tree
About how appium closes apps (resolved)
随机推荐
About the problem of APP flash back after appium starts the app - (solved)
Mongodb slice summary
MongoDB的用户管理总结
Digital IC Design SPI
How to reset Firefox browser
Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
工具箱之 IKVM.NET 项目新进展
高端了8年,雅迪如今怎么样?
Differences between MySQL storage engine MyISAM and InnoDB
[QNX hypervisor 2.2 user manual]6.3.4 virtual register (guest_shm.h)
飞桨EasyDL实操范例:工业零件划痕自动识别
PCAP学习笔记二:pcap4j源码笔记
The difference between cache and buffer
RecyclerView的数据刷新
PAcP learning note 1: programming with pcap
数字ic设计——SPI
ESP32 ① 编译环境
Day26 IP query items
File operation command
Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]