Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is command line compilation via ikvmc.exe no longer supported when statically converting Java bytecode to CIL? #613

Closed
kdaek21 opened this issue Nov 4, 2024 · 10 comments

Comments

@kdaek21
Copy link

kdaek21 commented Nov 4, 2024

I checked the contents of the comment that said to refer to 'https://github.com/orgs/ikvmnet/discussions/463' in the #612 I registered,

I saw the distinction IKVM.Runtime.Launcher.Run (string main, bool jar, string [] args, string rarg, IDictionary<string, string>properties), and in the comment there was something about Launcher, so I tried static conversion using ikvmc on the command line to see if the Spring Boot launcher part would be converted to IKVM.Runtime.Launcher.Run when using ikvmc for static conversion, but

Core library not found. Make sure the appropriate reference assemblies for the target environment are included. It only gives an error and does not convert. (It is the same even if I make a simple sample)

I looked it up and found that a similar issue was registered before, so I checked and it said to use ikvmReference. When I checked using ikvmReference, it seems to be a method of using jar files as libraries for .NET projects using Visual Studio.

Is there no longer a way to convert a class that contains a (Java) main function or a Java jar file that contains this class into a CIL exe file using ikvmc?

The IKVM tools used are IKVM-8.10.3-tools-net472-win-x64.

@wasabii
Copy link
Contributor

wasabii commented Nov 4, 2024

It is. But there are a lot of options you need to add. -reference to the ref assemblies of the runtime version you want to bind to.

@kdaek21
Copy link
Author

kdaek21 commented Nov 5, 2024

I found the default parameters for net472 version. If you do it like below, the conversion will work..
However, since only the assembly is created, the remaining necessary files must be created or copied separately to ensure normal operation. (Except for special cases such as Spring Boot)

ikvmc -r:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll" -r:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll" -runtime:"D:\Java\ikvm-jre8-net472\bin\IKVM.Runtime.dll" [classOrjar1] ... [classOrJarN]

  • 'D:\Java\ikvm-jre8-net472' is the path where IKVM-8.10.3-jre-net472-win-x64 is installed.

@wasabii
Copy link
Contributor

wasabii commented Nov 5, 2024

Those are possible paths. But probably not the ones you want. When building you probably want to bind against the reference assemblies from the appropriate target framework version.

@mengke2815
Copy link

I have the same problem,it donesn’t work

image

@kdaek21
Copy link
Author

kdaek21 commented Nov 15, 2024

To statically convert for .NET Core, I found the following.
Example) Static conversion for net8.0

ikvmc -target:library -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -runtime:"D:\Java\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -nostdlib -main:[Class name including the package containing the main function] [classOrjar1] ... [classOrJarN]

  • For net core, references are detailed, so in some cases you may need to add the -r option.
  • Since it is converted to a library, it is essential to specify the class name including the package that contains the main function.
  • [App name].runtimeconfig.json file must be created separately (copy one from ikvm-jdk or ikvm-jre, rename it, and use it)
  • Since the executable file that automatically uploads the dll to the dotnet core runtime environment is not created, you must use it in the dotnet [App name].dll format, or learn the API for running the .NET Core app in C/C++ and implement it directly in C/C++ and use it
  • For both the net472 method and the net core method, you must obtain peripheral files such as IKVM.Runtime and IKVM.Java from ikvm-jdk or ikvm-jre that are appropriate for each environment (IKVM.Java additionally varies depending on the OS environment, so checking the OS environment is essential)
  • In the net core method, when creating [App name].runtimeconfig.json, simply obtain one from ikvm-jdk or ikvm-jre and use it. Since the default setting is self-contained execution when using it by changing the name, you also need to bring in the dotnet core libraries in ikvm-jdk or ikvm-jre.

I ended up finding what I wanted myself, so I'll close this issue.

@kdaek21
Copy link
Author

kdaek21 commented Nov 15, 2024

I have the same problem,it donesn’t work

image

I was adding information about net core, and you answered it again..
net core needs to be compiled properly with the -nostdlib option.

@kdaek21 kdaek21 closed this as completed Nov 15, 2024
@mengke2815
Copy link

thanks

@mengke2815
Copy link

I have another problem,can you help me

image

@kdaek21
Copy link
Author

kdaek21 commented Nov 15, 2024

I have another problem,can you help me

image

net core requires more references than net472. Below is the compilation syntax that I tested with Tomcat. When compiling Tomcat...

System.Runtime.dll is required by default,
and Systme.Console.dll, System.Threading.dll, and System.Threading.Thread.dll were additionally required.

ikvmc -target:library -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Console.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Threading.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Threading.Thread.dll" -runtime:"D:\Java\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -recurse:"./lib" -nostdlib -main:"org.apache.catalina.startup.Bootstrap" bootstrap.jar tomcat-juli.jar

@mengke2815
Copy link

I have another problem,can you help me
image

net core requires more references than net472. Below is the compilation syntax that I tested with Tomcat. When compiling Tomcat...

System.Runtime.dll is required by default, and Systme.Console.dll, System.Threading.dll, and System.Threading.Thread.dll were additionally required.

ikvmc -target:library -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Console.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Threading.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Threading.Thread.dll" -runtime:"D:\Java\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -recurse:"./lib" -nostdlib -main:"org.apache.catalina.startup.Bootstrap" bootstrap.jar tomcat-juli.jar

oh,i understand,thanks very much~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants