• IKVM.NET_07_用户指南_IKVM.NET 字节码编译器(ikvmc.exe)


    ikvmc 将 Java 字节码转换成 .NET dll 文件或是 .exe 文件。

    本文内容

    • 用法
    • 选项
    • 备注
    • 例子

    用法

    ikvmc [ options ] classOrJarfile [ classOrJarfile ... ] 

    其中,

    • options 将在下面介绍。
    • classOrJarfile 是 Java .class 文件或 jar 文件,可以包含通配符(*.class)。

    选项

    1) -out:outputfile

    Specifies the name of the output file. Should have a .dll extension (if -target is library) or an .exe extension (if -target is exe or winexe). In most cases, if you omit this option, ikvmc will choose an output name based on the -target and the name of the input files. However, if you specify input files using wildcards, you must use this option to specify the output file.

    2) -assembly:assembly-name

    Specifies the name of the generated assembly. If omitted, the assembly name is (usually) the output filename.

    3) -target:target-type

    Specifies whether to generate an .exe or .dll. target-type is one of

    exe - generates an executable that runs in a Windows command window

    winexe - generates an .exe for GUI applications

    library - generates a .dll

    module - generates a .netmodule

    On Linux, there is no difference between exe and winexe.

    4) -keyfile :keyfilename  Uses keyfilename to sign the resulting assembly. 

    5) -version:M.m.b.r  Specifies the assembly version. 

    6) -main:classname  Specifies the name of the class containing the main method. If omitted and the -target is exe or winexe, ikvmc searches for a qualifying main method and reports if it finds one.

    7) -reference:library-filespec  If your Java code uses .NET API's, specify the dll's using this option. This option can appear more than once if more than one library is referenced. Wildcards are permitted (e.g. c:/libs/*.dll). 

    8) -recurse:filespec  Processes all files matching filespec in and under the directory specified by filespec. Example: -recurse:*.class 

    9) -nojni  Do not generate JNI stub for native methods 

    10) -resource:name=path  Includes path as a Java resource named name 

    11) -exclude:filename  filename is a file containing a list of classes to exclude 

    12) -debug  Generates debugging information in the output. Note that this is only helpful if the .class files contain debug information (compiled with the javac -g option). 

    13) -srcpath:path  Specifies the location of source code. Use with -debug. The package of the class is appended to the specified path to locate the source code for the class. 

    14) -Xtrace:name  Displays all tracepoints with name 

    15) -Xmethodtrace:methodname  Builds method trace into the specified output method.

    备注

    ikvmc 工具可以从 Java class 文件和 jar 文件生成 .NET 程序集。它可以把输入的 Java 字节码转换成 .NET CIL (公共中间语言)。可以生成如下 .NET 文件:

    1) 指定 "-target:exe" 或 "-target:winexe" 选项,可以生成 .NET 可执行程序;

    2) 指定 "-target:library" 选项,可以生成 .NET 程序集文件;

    3) 指定 "-target:module" 选项,可以生成 .NET 模块。

    Java 应用程序通常是由一些 jar 文件组成。ikvmc 可以处理输入的 jar 文件和 class 文件,来生成一个单独的 .NET 可执行程序或程序集。例如,一个由 main.jar、lib1.jar 和 lib2.jar 组成的 Java 应用程序可以被转换成一个 .NET main.exe 文件。当处理多个输入的 jar 文件时,这包括重复的类和资源,ikvmc将使用它遇到的第一个 class 或资源文件,而忽略之后命令行中出现的文件。因此,jar 文件的顺序很重要。

    注意:When converting a Java application with ikvmc, for best results, list the jars on the ikvmc command line in the same order that they appear in the Java application's classpath.

    当用 ikvmc 转换一个 java 应用程序时,最好的方式,在 ikvmc 命令行中列出的 jar 文件的顺序与 Java 应用程序的classpath出现的顺序相同。

    例子

    命令 "ikvmc myProg.jar" 将查找 myProg.jar 中的 main 方法,如果找到,就产生一个 .exe 文件,否则,产生一个 .dll 文件。

    ikvmc -out:myapp.exe -main:org.anywhere.Main -recurse:bin/*.class lib/mylib.jar

    该命令,处理所有输入的 .class 和 bin 目录下的文件,以及 lib 目录下的 jar 文件,并且把 "org.anywhere.Main" 作为 main 方法,生成一个名为 "myapp.exe" 可执行程序。

  • 相关阅读:
    C++中左移<<的使用
    学会构造素数序列
    有关lower_bound()函数的使用
    Codeforces Round #166 (Div. 2)
    暴力swap导致TLE问题解决办法
    memset的正确使用
    Codeforces Round #297 (Div. 2)
    Codeforces Round #170 (Div. 2)B
    Codeforces Round #176 (Div. 2)
    C/C++ sort函数的用法
  • 原文地址:https://www.cnblogs.com/liuning8023/p/2156344.html
Copyright © 2020-2023  润新知