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>
jeroen.frijters@gmail.com - 23 Jan 2006 17:01 GMT
.NET will only load assemblies from specific locations, not the current
directory. So you need to copy toolbox.dll to the ikvm.exe directory or
put it into the GAC.
Regards,
Jeroen
> I have a bad IKVM.net problem. I want to use .net libraries from java
> code.
[quoted text clipped - 132 lines]
> at TBClient.main (Unknown Source)
> C:\ikvm\test>
jukkaviitala@hotmail.com - 24 Jan 2006 18:27 GMT
Thanks for Your answer, but I check this chance couple times and effect
is same every time. I'm comparatively sure that reason is not wrong
directory.
jukkaviitala@hotmail.com - 25 Jan 2006 17:08 GMT
Thanks Jeroen! Reason found and this works fine:
c:\ikvm\bin\ikvm -cp c:\ikvm\test\toolbox.jar;. TBClient
Regards,
Jukka Viitala
Roedy Green - 25 Jan 2006 20:21 GMT
>.NET will only load assemblies from specific locations, not the current
>directory. So you need to copy toolbox.dll to the ikvm.exe directory or
>put it into the GAC.
>
>Regards,
>Jeroen
Just saying hi. I met you 6 years or so ago at the Colorado Software
conference. I ran into your name yesterday when I was composing a
lislt of COM tools and came across your IKVM.net mono project.
You did some tools for manipulating class files. The links have gone
dead. Are they still available?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.