You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C#应用中通过IKVM调用Quarkus构建的JAR文件?

Fix: Access Quarkus JAR Classes from .NET via IKVM

Key Issue: Quarkus Default Build Produces a Fat Runnable JAR

Quarkus's default mvn clean package generates an executable fat JAR where your application classes are nested inside BOOT-INF/classes/, and dependencies are in BOOT-INF/lib/. IKVM doesn't automatically scan these nested directories, which is why you can't access your classes—unlike the flat, simple "helloworld" sample JAR.

Step 1: Configure Quarkus to Build a Library JAR

Modify your Quarkus project's pom.xml to generate a standard library JAR (not executable) with your classes at the root level:

Option 1: Add Package Type Property

Add this to the <properties> section:

<properties>
    <!-- ... other existing properties ... -->
    <quarkus.package.type>lib</quarkus.package.type>
</properties>

Option 2: Configure the Quarkus Maven Plugin

Or explicitly set the package type in the plugin configuration:

<build>
    <plugins>
        <plugin>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-maven-plugin</artifactId>
            <version>${quarkus.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>build</goal>
                    </goals>
                    <configuration>
                        <packageType>lib</packageType>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Step 2: Rebuild the Quarkus JAR

Run the build command again:

mvn clean package

Verify the JAR contents with jar tf your-project-name-1.0.0.jar—you should see your class files directly under their package paths (e.g., com/yourcompany/YourClass.class) instead of nested in BOOT-INF/classes/.

Step 3: Update .NET Project to Reference the Library JAR

In your .NET csproj, ensure you're referencing this new library JAR instead of the old fat JAR:

<ItemGroup>
    <IkvmReference Include="path/to/your-project-name-1.0.0.jar" />
</ItemGroup>

Additional Checks

  • Public Classes: Ensure your Java classes and methods are marked public—IKVM can't access non-public members from the JAR in .NET.
  • IKVM Version: Use the latest stable IKVM NuGet packages (IKVM, IKVM.Maven.Sdk) to avoid compatibility issues.
  • Dependencies: If your Quarkus app uses external libraries, add them as separate IkvmReference entries in your csproj (IKVM won't pull nested dependencies from the fat JAR automatically).

内容的提问来源于stack exchange,提问作者AppWebDeveloper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:52:39