Re: [Ikvm-developers] ikvmstub questions/problems
Brought to you by:
jfrijters
From: <er...@fr...> - 2010-12-23 10:16:35
|
Hi Jeroen, first of all, thanks for replying me. I want to do some call of a .NET api from a java application. That's why I'm use the ikvmstub generated stub jar at runtime. If I don't, I have a NoClassDefFoundError. Just to add some information on how I'm doing things. Here are the step I do the things: - Compiling my .NET api with MS Visual => it generates c:\dotnet\classlibrary1\bin\debug\classlibrary1.dll - go to my c:\java\program1\lib - execute ikvmstub -nostdlib -r:"c:\Windows\MICROSOFT.NET\Framework\v2.0.50727\mscorlib.dll" -r:"c:\Windows\MICROSOFT.NET\Framework\v2.0.50727\System.dll" "c:\dotnet\classlibrary1\bin\debug\classlibrary1.dll" - execute ikvmstub "c:\Windows\MICROSOFT.NET\Framework\v2.0.50727\mscorlib.dll" - execute ikvmstub "c:\Windows\MICROSOFT.NET\Framework\v2.0.50727\System.dll" - it succeed in generating a classlibrary1.jar, mscorlib.jar and System.jar - I compile (with javac) my program with adding to classpath classlibary1.jar, mscorlib.jar and System.jar - it succeed in generating program1.class - copying classlibrary1.dll to ikvm bin dir (to let it know the assembly) - then run: ikvm -cp .;..\lib\classlibrary1.jar program1 Then I got this error: Exception in thread "main" java.lang.LinkageError: Loader constraints violated ( arg 0): cli.com.example.MyClass1.<init>(Lcom.example.IBitUser;)V at progam1.main(program1.java:26) MyClass1 constructor needs a IBitUser class as parameter. in my main, I pass to it an implementation of IBitUser. The implementation class is defined in my classlibrary dotnet API, as its interface. But the construction of this implementation class is done in java through something like: import cli.com.example.BitUserImplementation; import cli.com.example.MyClass1; ... BitUserImplementation bui = new BitUserImplementation(); MyClass1 myClass1 = new myClass1(bui); // error here at runtime ... Any idea? Am I doing something wrong? when you said: > A "Loader constraints violated" LinkageError typically means that you > have two different versions of the same class loaded (in this case > IBitUser). What is the behaviour when IBitUser is an interface and BitUserImplementation an implementation of this interface? Is it considered as two different version of the same class ? > Now given the name of the type involved (cli.Something), I'm guessing > that you are using the ikvmstub generated stub jars at runtime (which > is generally not what you want). Yes, perhaps it's not what I want, but how can I compile my java program without the ivkmstub generated jar? Is there any other way of doing this? ----- "Jeroen Frijters" <je...@su...> a écrit : > Hi, > > A "Loader constraints violated" LinkageError typically means that you > have two different versions of the same class loaded (in this case > IBitUser). > > Now given the name of the type involved (cli.Something), I'm guessing > that you are using the ikvmstub generated stub jars at runtime (which > is generally not what you want). > > You probably need to sort out your class loader issues. > > Regards, > Jeroen > > > -----Original Message----- > > From: er...@fr... [mailto:er...@fr...] > > Sent: Tuesday, December 21, 2010 1:53 PM > > To: ikv...@li... > > Subject: [Ikvm-developers] ikvmstub questions/problems > > > > Hello, > > > > using ikvm v0.44.0.5, on windows XP Pro environment, with .Net > Framework > > v2.0 (I also have 3.5 installed) > > > > I'm trying to make some call to a .NET library in a java program > (ran on > > a Tomcat Server). > > First simples examples looks great. > > So I started my tomcat server with ikvm (v.0.44.0.5), everything > look > > great. Simple call to .NET library works. (like a call to > > cli.System.Console.Writeline) > > > > But I do have a problem. > > For example, here's a bit of my .NET class I want to use: > > > > public interface IBitUser : ICloneable > > { > > String ID { get; set; } > > MUserType UserType { get; } > > int MaxBitSize { get; } > > > > void ReadFrom(BitUserBytesStreamReader streamReader); > > void WriteTo(BitUserBytesStreamWriter streamWriter); > > } > > > > with implementation of this interface BitUserModel1 > > > > > > then a BitUserFactory: > > public class BitUserFactory : IBitUserFactory > > { > > > > private int maxBitSize; > > private IDictionary mapNbBlock = new Hashtable(); > > > > public BitUserFactory(IDictionary mapUserTypeNbBlock1) > > { > > this.mapNbBlock = mapUserTypeNbBlock1; > > maxUserBitSize = 0; > > foreach (Object t in mapNbBlock.Values) > > { > > Type t2 = t as Type; > > IBitUser user1 = (IBitUser)t2.GetConstructor(new > Type[] > > { }).Invoke(new Object[] { }); //mapping from an enum to a Type > > maxUserBitSize = Math.Max(maxUserBitSize, > > user1.MaxBitSize); > > } > > } > > > > public IBitUser Read() //read a User... sample method... in > real > > world it's more complicated... I should use the mapNbBlock... > > { > > IBitUser user = > > > (IBitUser)((Type)mapNbBlock[MUserType.USER_TYPE1]).GetConstructor(new > > Type[] { }).Invoke(new Object[] { }); > > return user; > > } > > } > > > > in my java code I do (in a servlet class): > > > > protected void doGet(HttpServletRequest request, > HttpServletResponse > > response) throws ServletException, IOException { > > Hashtable dictionary = new Hashtable(); > > IBitUser UserModel1 = new BitUserModel1(); > > > > dictionary.Add(MUserType.USER_TYPE1, UserModel1.GetType()); > > > > BitUserFactory tf = new BitUserFactory(dictionary); // just > > initializing the BitUserFactory... > > IBitUser t = tf.Read(); // Runtime Error here > > Console.WriteLine((String)((IBitUser)t).get_ID()); > > } > > > > > > And then I've got this error: > > java.lang.LinkageError: Loader constraints violated (return type): > > > cli.Com.Example.User.BitUserFactory.Read()Lcli.Com.Example.User.IBitUser > > ; > > com.example.TestServlet.doGet(TestServlet.java:53) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:690) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:804) > > > > > > I had a similar problem on another class, when the method prototype > of > > the class return an Interface, an at the call step, return a real > object > > implementing this interface. > > > > It seems that it does not detect that my BitUserModel1 inherit from > > IBitUser... > > Any tips to get rid of this problem ? or code like this that works? > Did > > I miss something? > > I don't understand where's the mistake. > > > > thanks, > > > > -- > > Martin BdC > > > > > ------------------------------------------------------------------------ > > ------ > > Lotusphere 2011 > > Register now for Lotusphere 2011 and learn how to connect the dots, > take > > your collaborative environment to the next level, and enter the era > of > > Social Business. > > http://p.sf.net/sfu/lotusphere-d2d > > _______________________________________________ > > Ikvm-developers mailing list > > Ikv...@li... > > https://lists.sourceforge.net/lists/listinfo/ikvm-developers |