Skip to content

Commit 575a6f7

Browse files
authored
Add ability to provide arguments to the JVM when using executable Java apps (#888)
1 parent 5280275 commit 575a6f7

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/CommunityToolkit.Aspire.Hosting.Java/JavaAppExecutableResourceOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public class JavaAppExecutableResourceOptions
2424
/// Gets or sets the arguments to pass to the Java application.
2525
/// </summary>
2626
public string[]? Args { get; set; } = null;
27+
28+
/// <summary>
29+
/// Gets or sets the arguments to pass to the Java Virtual Machine.
30+
/// </summary>
31+
public string[]? JvmArgs { get; set; } = null;
2732
}

src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static IResourceBuilder<JavaAppExecutableResource> AddJavaApp(this IDistr
3535
: ["-jar", options.ApplicationName];
3636
#pragma warning restore CS8601 // Possible null reference assignment.
3737

38+
if (options.JvmArgs is { Length: > 0 })
39+
allArgs = [.. options.JvmArgs, .. allArgs];
40+
3841
workingDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, workingDirectory));
3942
var resource = new JavaAppExecutableResource(name, "java", workingDirectory);
4043

tests/CommunityToolkit.Aspire.Hosting.Java.Tests/ExecutableResourceCreationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public async Task AddJavaAppContainerDetailsSetOnResource()
7777
{
7878
ApplicationName = "test.jar",
7979
Args = ["--test"],
80+
JvmArgs = ["-Dtest"],
8081
OtelAgentPath = "otel-agent",
8182
Port = 8080
8283
};
@@ -101,9 +102,8 @@ public async Task AddJavaAppContainerDetailsSetOnResource()
101102
Assert.True(resource.TryGetLastAnnotation(out CommandLineArgsCallbackAnnotation? argsAnnotations));
102103
CommandLineArgsCallbackContext context = new([]);
103104
await argsAnnotations.Callback(context);
104-
Assert.All(options.Args, arg => Assert.Contains(arg, context.Args));
105-
Assert.Contains("-jar", context.Args);
106-
Assert.Contains(options.ApplicationName, context.Args);
105+
106+
Assert.Equal([..options.JvmArgs, "-jar", options.ApplicationName, ..options.Args], context.Args);
107107
}
108108

109109
[Fact]

0 commit comments

Comments
 (0)