Using Mogre with Java

Schmelly

10-11-2006 14:05:31

Hello together,

right now im experimenting how to develop Mogre based Applications with Java. For this i use the ikvm java virtual machine. The ikvm project provides tools for generating java stubs with which you can call .NET assemblies from java.

I wrote a minimal test application in java that tries just to create an Ogre Root object (i put the java classes directly in the OgreSDK/bin/release folder). The rather simple code is shown below:

package test;

import cli.Mogre.Root;

public class Test {

public static void main(String[] args) {
new Root();
}

}


When i now try to run my little application out of the OgreSDK/bin/release folder i get the following exception:

Could not load file or assembly 'Mogre, Version=0.1.7.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

However everything works as expected when i use the .NET Console as follows:

package test;

import cli.System.Console;

public class Test {

public static void main(String[] args) {
Console.get_Out().Write("test");
}

}


Im a little bit confused here since i started my application right out of the bin/release folder and thought the appropriate Mogre dlls should be found... The next thing i tried was to install the Mogre.dll in the .NET assembley cache but this failed with the following error:

Unable to add the selected assembly. The assembly must have a strong name (name, version and public key).


Im a little bit stucked here since i dont know .NET enough. Does anybody have an idea where the problem might lie?

thanks in advance,

David

Bekas

10-11-2006 15:46:28

Whoa, cool project! I downloaded ikvmbin-0.30.0.0.zip but when I execute "ikvmstub mogre.dll' I get:System.BadImageFormatException: The format of the file 'mogre.dll' is invalid.
How did you produce the stubs?


You may be interested to know that there is a java wrapper for Ogre: http://ogre4j.org

Schmelly

10-11-2006 16:13:48

Hm i dont get that error. What .NET version do you use?

My output looks like this:

schmelly@workstation /cygdrive/d/Programme/OgreSDK/bin/release
$ ikvmstub.exe Mogre.dll
Skipping: Mogre.Pair`2



I know about Ogre4J thanks. But i think it would be great to be able to integrate Java with .NET, especially for tool development. Since im mainly developing in Java im missing Frameworks like EMF or GMF :wink:

www.eclipse.org/emf
www.eclipse.org/gmf


David

Schmelly

10-11-2006 16:18:39

PS: if you arent able to generate the required java stubs i could send them to you via mail

Bekas

10-11-2006 16:36:21

Mogre requires .NET 2.0, are you trying to use it with Mono ?

Schmelly

10-11-2006 16:49:35

no im using Microsoft .NET 2.0

Bekas

10-11-2006 16:56:13

Ah, I have 1.1 installed too so I needed to do this.

Bekas

10-11-2006 19:15:55

Hey, it worked for me. Do the demos execute fine?

IKVM is cooler than a frozen escimoe! :) What are its limitations (it doesn't handle .NET generics, right ?)

Schmelly

10-11-2006 20:16:56

did you start a java application with ikvm or did you create .net assemblies from the java .class files?

im not able to run a java program with ikvm and ogre classes...

Bekas

10-11-2006 23:07:12

did you start a java application with ikvm or did you create .net assemblies from the java .class files?
Both succeeded. But my java skills are rusty and I couldn't make ikvm find the Test class without removing the package declaration:
import cli.Mogre.Root;

public class Test {

public static void main(String[] args) {
new Root();
}

}

Schmelly

10-11-2006 23:22:58

hm strange

i get the same exception as shown in the first post...


did you install your *ogre.dlls in the assembly cache?

Bekas

10-11-2006 23:37:16

Try adding 'c:\OgreSDK\bin\release' to the PATH environment variable.

If you still get the exception, execute this file from inside the bin\release directory and let me know if it runs ok or not.

Schmelly

10-11-2006 23:53:19

same error for the java app :? the example apps work ok

Exception in thread "main" java.lang.NoClassDefFoundError: cli.Mogre.Root (Could not load file or assembly 'Mogre, Versi
on=0.1.7.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Das System kann die angegebene Datei nicht
finden.)
at IKVM.NativeCode.java.lang.VMClassLoader.defineClassImpl(Unknown Source)
at java.lang.VMClassLoader.defineClassImpl(VMClassLoader.java)
at java.lang.VMClassLoader.defineClassWithTransformers(VMClassLoader.java:105)
at java.lang.ClassLoader.defineClass(ClassLoader.java:468)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.findClass(URLClassLoader.java:617)
at java.lang.ClassLoader.loadClass(ClassLoader.java:342)
at java.lang.ClassLoader$1.loadClass(ClassLoader.java)
at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
at IKVM.Internal.ClassLoaderWrapper.LoadClassImpl(Unknown Source)
at IKVM.Internal.ClassLoaderWrapper.LoadClassByDottedNameFastImpl(Unknown Source)
at IKVM.Runtime.ByteCodeHelper.LoadTypeWrapper(Unknown Source)
at IKVM.Runtime.ByteCodeHelper.DynamicNewCheckOnly(Unknown Source)
at test.Test.main(Test.java:13)

Bekas

11-11-2006 00:46:22

Ok I found the problem. For some reason, the IKVM binaries need to be in 'C:\OgreSDK\bin\release' folder too.
I had copied the IKVM binaries there from the start and it worked. When I tried to run IKVM from another directory I got the exception that you get.

Schmelly

11-11-2006 08:13:46

ahhhh the ikvm.exe as well...

this is a bit weird but hey, expect some neat eclipse integration in the future :wink:


thank you Bekas!

Schmelly

11-11-2006 08:52:25

i just ported the minimal application from the wiki sucessfully to java (without framelistener support for now)

this rocks :D