Connection problem with IKVM.net and .net DLL

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>
 
J

jeroen.frijters

..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.

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>
 
J

jukkaviitala

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.
 
J

jukkaviitala

Thanks Jeroen! Reason found and this works fine:

c:\ikvm\bin\ikvm -cp c:\ikvm\test\toolbox.jar;. TBClient

Regards,
Jukka Viitala
 
R

Roedy Green

.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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top