ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.15k stars 110 forks source link

Migrate to new version of IKVMC from 7.2 to 8.7 #471

Closed amjathrahman closed 5 months ago

amjathrahman commented 5 months ago

Hi Team,

We are using IKVMC version 7.2 and converting the JT400.jar to dll and used in our project, Due to recent security find we want to use JT400 with SSL option but unfortunately when we use IKNMC version 7.2 to convert the jar to dll it was always sending the TLS version as 1.0 in client hello, So we want to use that latest version of IKVMC version 8.7.3 but we are getting the below error

image

Can you please help me with this, it's bit urgent as audit is going to happen soon

With Thanks Amjath

NightOwl888 commented 5 months ago

It is not recommended to use the command line to do the conversion unless you have a compelling reason to. Since this package is on Maven, I suggest using MavenReference instead. It can be specified by hand editing your MSBuild project file. Note that it must be the new SDK-style project format. Here is an example.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IKVM" Version="8.7.3" />
    <!-- Required for MavenReference support -->
    <PackageReference Include="IKVM.Maven.Sdk" Version="1.6.7" />
  </ItemGroup>

  <ItemGroup>
    <!-- Specify any packages you want to compile from Maven here -->
    <MavenReference Include="net.sf.jt400:jt400" Version="20.0.6" />
  </ItemGroup>

</Project>
naveenkv66 commented 5 months ago

Hi @NightOwl888 , Below is my item group,

MyClient SSLClient 0.0.1-SNAPSHOT

I have added SSLClient-0.0.1-SNAPSHOT.jar in .net 6 console project root directory. Build succeeded, where can I see the output of SSLClient-0.0.1-SNAPSHOT.jar to .NET dll. How can I call my Java library function in my .NET code?

ivkmTest2

ivkmTest1

naveenkv66 commented 5 months ago

Also if tried to add jt400 reference as you mentioned above, getting the below error. image

csproj: image

NightOwl888 commented 5 months ago

How can I call my Java library function in my .NET code?

That part hasn't changed. You call the Java code by accessing the package location like a namespace (i.e. net.jt.). You should be able to see all of the types in the package that have been converted.

NightOwl888 commented 5 months ago

Also if tried to add jt400 reference as you mentioned above, getting the below error. image

csproj: image

I got the same error, but wasn't sure if it was something on my setup. @wasabii - any ideas?

amjathrahman commented 5 months ago

Hi @NightOwl888 ,

Thanks for the response, I also getting the same error while doing the build

image


IKVM.Maven.Sdk.targets(96,9): error : DependencyResolutionException: The following artifacts could not be resolved: com.sun:tools:jar:1.8.0, com.sun:tools:jar:1.8.0: Could not find artifact com.sun:tools:jar:1.
IKVM.Maven.Sdk.targets(96,9): error :    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(RepositorySystemSession session, DependencyRequest request) in DefaultRepositorySystem.ja
IKVM.Maven.Sdk.targets(96,9): error :    at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.ResolveCompileDependencyGraph(IkvmMavenEnvironment maven, RepositorySystemSession session, IList`1 repositories, IList`
IKVM.Maven.Sdk.targets(96,9): error :    at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.ResolveReferences(IList`1 repositories, IList`1 items) in /_/src/IKVM.Maven.Sdk.Tasks/MavenReferenceItemResolve.cs:line
IKVM.Maven.Sdk.targets(96,9): error :    at IKVM.Maven.Sdk.Tasks.MavenReferenceItemResolve.Execute() in /_/src/IKVM.Maven.Sdk.Tasks/MavenReferenceItemResolve.cs:line 160
IKVM.Maven.Sdk.targets(96,9): error : ArtifactResolutionException: The following artifacts could not be resolved: com.sun:tools:jar:1.8.0, com.sun:tools:jar:1.8.0: Could not find artifact com.sun:tools:jar:1.8.
IKVM.Maven.Sdk.targets(96,9): error :    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(RepositorySystemSession session, Collection requests) in DefaultArtifactResolver.java:line 2
IKVM.Maven.Sdk.targets(96,9): error :    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(RepositorySystemSession session, DependencyRequest request) in DefaultRepositorySystem.ja
IKVM.Maven.Sdk.targets(96,9): error : ArtifactNotFoundException: Could not find artifact com.sun:tools:jar:1.8.0 at specified path C:\Users\AmjathKhanAbdulRahim\.nuget\packages\ikvm.maven.sdk\1.6.7\tasks\net472
IKVM.Maven.Sdk.targets(96,9): error : 
IKVM.Maven.Sdk.targets(96,9): error :
wasabii commented 5 months ago

Looks like this jt400 project depends on a few other projects, ultimately termianting with com.sun.tools:

net.sf.jt400:jt400:20.0.6:compile
+- javax.servlet:javax.servlet-api:4.0.1:provided
\- org.apache.maven.plugins:maven-antrun-plugin:3.1.0:provided
   +- org.codehaus.plexus:plexus-utils:3.4.1:provided
   \- org.apache.ant:ant:1.10.12:provided
      +- org.apache.ant:ant-launcher:1.10.12:provided
      \- com.sun:tools:1.8.0:system

Using the system scope. So, org.apache.ant:ant:1.10.12 is depending on com.sun:tools:1.8.0:system. However, according to the Maven documentation, the "system" scope functionality is a) known to break with different JVMs and Operating Systems and b) deprecated no longer to be used. So, technically, this is a bug with the org.apache.ant:ant:1.10.12 package, and should probaably be reported to and addressed by them.

The recommended work around on the Maven side is to use an exclusion to eliminate the system dependency. However, https://github.com/ikvmnet/ikvm-maven/issues/48 isn't yet completed (and I just made it).

So for now, I would recommend using IkvmReference directly. IKVM.Maven.Sdk release is incoming.

naveenkv66 commented 5 months ago

@wasabii I am using the Ikvm reference directly and getting exceptions like below.

csproj File: IKMReference

Output Directory: jt400 dll generated Successfully like below. OutputDirectory

And i am consuming the dll like below image

But when I try to access the as400 library inside my code and get the below exception

Exception

NightOwl888 commented 5 months ago

@naveenkv66 - Please post the stack trace as text. The images are not very helpful. It is also a lot of work for us to convert the screenshots back into text on our end to try to debug.

naveenkv66 commented 5 months ago

@NightOwl888

Exception message: The type initializer for 'com.ibm.as400.access.AS400' threw an exception.

Stack trace: at com.ibm.as400.access.AS400..ctor(String systemName, String userId) at AS400IVKM8_7.Form1.Connect_Click(Object sender, EventArgs e) in C:\Official\AS400ConnectionApp\AS400IVKM8_7\Form1.cs:line 32

wasabii commented 5 months ago

Support for Maven Exclusion in IKVM.Maven.Sdk was added, and that would be the appropriate workaround with the initial Maven issue discovered. As far as I can tell that was the only concrete issue that was discovered in this issue. The rest just seems to be the user misunderstanding what is going on, and those questions were appropriately answered.

So, going to go ahead and close this for now. Reopen, or submit another issue, if a more specific problem can be found.