2012-04-24 27 views
1

我想爲System.Web創建一個存根,並在我的java代碼中使用HttpContext,然後就可以使用它。我曾嘗試以下:如何爲System.Web創建工作的ikvmstub

文件夾結構

  • 程序[文件夾]
    • IKVM-7.0.4335.0 [文件夾]
    • 的compile.bat
    • test.java
    • IKVM.OpenJDK.Core.dll
    • IKVM.Runtime.dll

Java類test.java

import cli.System.Web.HttpContext; 

public class test 
{ 
    public static void main(String args[]) 
    { 
     HttpContext.get_Current().get_Items().get_Item("MyKey"); 
     System.out.println("Hello World!"); 
    } 
} 

編譯的compile.bat

ikvm-7.0.4335.0\bin\ikvmstub mscorlib 
ikvm-7.0.4335.0\bin\ikvmstub System.Web 
javac test.java -classpath mscorlib.jar;System.Web.jar 
ikvm-7.0.4335.0\bin\ikvmc -target:exe -reference:System.Web.dll test.class 
test.exe 
pause 

如果我運行的compile.bat它會輸出:

Warning IKVMC0100: class "cli.System.Collections.IDictionary" not found Link Error: Method "cli.System.Web.HttpContext.get_Items()Lcli.System.Collection s.IDictionary;" has a return type "cli.System.Collections.IDictionary, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" instead of type "cli.System.Collections.IDictionary (unknown assembly)" as expected by "test "

我也嘗試直接爲「C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ System.Web.dll」創建存根,但隨後出現此錯誤:

Error: unable to load assembly 'C:\Program Files (x86)\Reference Assemblies\Micr osoft\Framework.NETFramework\v4.0\System.Web.dll' as it depends on a higher version of mscorlib than the one currently loaded

然後我試圖創建一個存根 「C:\ Program Files文件(x86)的\參考大會\微軟\ Framework.NETFramework \ V4.0 \ mscorlib.dll中」,並得到:

ikvmstub "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll" Warning: assembly "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framewo rk.NETFramework\v4.0\mscorlib.dll" is ignored as previously loaded assembly "C: \Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll" has the same identit y "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

有沒有人試過這個,併成功?

回答

0

我自己找到答案。我沒有引用mscorlib.dll,因爲我認爲它是自動引用的。所以,如果我更改以下行,它的工作原理:

ikvm-7.0.4335.0\bin\ikvmc -target:exe -reference:System.Web.dll test.class

ikvm-7.0.4335.0\bin\ikvmc -target:exe -reference:mscorlib.dll -reference:System.Web.dll test.class