如何在C#应用中通过IKVM调用Quarkus构建的JAR文件?
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
IkvmReferenceentries in your csproj (IKVM won't pull nested dependencies from the fat JAR automatically).
内容的提问来源于stack exchange,提问作者AppWebDeveloper

