J
jukkaviitala
I have a bad IKVM.net problem. I want to use .net libraries from java
code.
Concept works well, but my own compiled .net library (toolbox.dll) not
work calling from java code and it's giving to me
"java.lang.NoClassDefFoundError".
I use newest IKVM.net version 0.22.
Regards,
Jukka Viitala
Please find below my full code: TBClient.java, Toolbox.cs and
build.bat.
---------------------------------------------------------------
TBClient.java:
===========
import java.io.*;
import cli.System.IO.*;
import cli.System.Environment;
import cli.Toolbox.Connection;
public class TBClient {
public static void main(java.lang.String[] args) {
System.out.println("TBClient - program start.");
System.out.println("TBClient - Init class from DOTNET system dll");
cli.System.IO.DirectoryInfo dirinfo = new
cli.System.IO.DirectoryInfo(Environment.get_CurrentDirectory());
FileInfo[] files = dirinfo.GetFiles();
System.out.println("TBClient - Init DOTNET OK. Current directory: "
+ Environment.get_CurrentDirectory());
System.out.println("TBClient - Init class from toolbox.dll");
cli.Toolbox.Connection cn = new cli.Toolbox.Connection();
System.out.println("TBClient - Init OK");
System.out.println("TBClient - program end.");
}
}
---------------------------------------------------------
Toolbox.cs
===========
using System;
namespace Toolbox
{
public class Connection
{
public static void Main()
{
Console.WriteLine("Regards from .net server.");
}
public int MyDotNetMethod(int p_iValue)
{
return 123 + p_iValue;
}
}
}
'
---------------------------------------------------------
build.bat
===========
@echo.
:: @rem Copy IKVM dll's to this directory so we can run the executable
@copy c:\ikvm\bin\*.dll >nul:
@echo.
@rem Build dll from Toolbox.cs.
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library
/r:System.dll /out:toolbox.dll *.cs
@echo.
:: @echo Generating mscorlib.jar ...
:: @c:\ikvm\bin\ikvmstub mscorlib.dll
@echo.
@echo Generating toolbox.jar ...
@c:\ikvm\bin\ikvmstub toolbox.dll
@echo.
@echo Compiling *.java ...
"C:\Program Files\Java\jdk1.5.0_06\bin\javac" -classpath
mscorlib.jar;toolbox.jar TBClient.java
@echo.
@echo Run java program ...
@c:\ikvm\bin\ikvm TBClient
:done
---------------------------------------------------------
And the result is (running cmd.exe):
====================================
C:\ikvm\test>build
C:\ikvm\test>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc
/t:library /r:Syst
em.dll /out:toolbox.dll *.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
Generating toolbox.jar ...
Compiling *.java ...
C:\ikvm\test>"C:\Program Files\Java\jdk1.5.0_06\bin\javac" -classpath
mscorlib.j
ar;toolbox.jar TBClient.java
Run java program ...
TBClient - program start.
TBClient - Init class from DOTNET system dll
TBClient - Init DOTNET OK. Current directory: C:\ikvm\test
TBClient - Init class from toolbox.dll
Exception in thread "main" java.lang.NoClassDefFoundError:
cli.Toolbox.Connectio
n
at cli.JavaException.NoClassDefFoundError (Unknown Source)
at cli.IKVM.Runtime.ByteCodeHelper.LoadTypeWrapper (Unknown
Source)
at cli.IKVM.Runtime.ByteCodeHelper.DynamicNewCheckOnly (Unknown
Source)
at TBClient.main (Unknown Source)
C:\ikvm\test>
code.
Concept works well, but my own compiled .net library (toolbox.dll) not
work calling from java code and it's giving to me
"java.lang.NoClassDefFoundError".
I use newest IKVM.net version 0.22.
Regards,
Jukka Viitala
Please find below my full code: TBClient.java, Toolbox.cs and
build.bat.
---------------------------------------------------------------
TBClient.java:
===========
import java.io.*;
import cli.System.IO.*;
import cli.System.Environment;
import cli.Toolbox.Connection;
public class TBClient {
public static void main(java.lang.String[] args) {
System.out.println("TBClient - program start.");
System.out.println("TBClient - Init class from DOTNET system dll");
cli.System.IO.DirectoryInfo dirinfo = new
cli.System.IO.DirectoryInfo(Environment.get_CurrentDirectory());
FileInfo[] files = dirinfo.GetFiles();
System.out.println("TBClient - Init DOTNET OK. Current directory: "
+ Environment.get_CurrentDirectory());
System.out.println("TBClient - Init class from toolbox.dll");
cli.Toolbox.Connection cn = new cli.Toolbox.Connection();
System.out.println("TBClient - Init OK");
System.out.println("TBClient - program end.");
}
}
---------------------------------------------------------
Toolbox.cs
===========
using System;
namespace Toolbox
{
public class Connection
{
public static void Main()
{
Console.WriteLine("Regards from .net server.");
}
public int MyDotNetMethod(int p_iValue)
{
return 123 + p_iValue;
}
}
}
'
---------------------------------------------------------
build.bat
===========
@echo.
:: @rem Copy IKVM dll's to this directory so we can run the executable
@copy c:\ikvm\bin\*.dll >nul:
@echo.
@rem Build dll from Toolbox.cs.
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc /t:library
/r:System.dll /out:toolbox.dll *.cs
@echo.
:: @echo Generating mscorlib.jar ...
:: @c:\ikvm\bin\ikvmstub mscorlib.dll
@echo.
@echo Generating toolbox.jar ...
@c:\ikvm\bin\ikvmstub toolbox.dll
@echo.
@echo Compiling *.java ...
"C:\Program Files\Java\jdk1.5.0_06\bin\javac" -classpath
mscorlib.jar;toolbox.jar TBClient.java
@echo.
@echo Run java program ...
@c:\ikvm\bin\ikvm TBClient
:done
---------------------------------------------------------
And the result is (running cmd.exe):
====================================
C:\ikvm\test>build
C:\ikvm\test>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc
/t:library /r:Syst
em.dll /out:toolbox.dll *.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
Generating toolbox.jar ...
Compiling *.java ...
C:\ikvm\test>"C:\Program Files\Java\jdk1.5.0_06\bin\javac" -classpath
mscorlib.j
ar;toolbox.jar TBClient.java
Run java program ...
TBClient - program start.
TBClient - Init class from DOTNET system dll
TBClient - Init DOTNET OK. Current directory: C:\ikvm\test
TBClient - Init class from toolbox.dll
Exception in thread "main" java.lang.NoClassDefFoundError:
cli.Toolbox.Connectio
n
at cli.JavaException.NoClassDefFoundError (Unknown Source)
at cli.IKVM.Runtime.ByteCodeHelper.LoadTypeWrapper (Unknown
Source)
at cli.IKVM.Runtime.ByteCodeHelper.DynamicNewCheckOnly (Unknown
Source)
at TBClient.main (Unknown Source)
C:\ikvm\test>