Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for adding default launch arguments #446

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ By default it will generate next artifacts in `${outputDirectory} ` folder:
### Plugin configuration properties

| Property | Mandatory | Default value | Description |
| -------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|----------------------------|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `additionalModulePaths` | :x: | `[]` | Additional module paths for `jdeps`. |
| `additionalModules` | :x: | `[]` | Additional modules to the ones identified by `jdeps` or the specified with `modules` property. |
| `additionalResources` | :x: | `[]` | Additional files and folders to include in the bundled app. |
Expand Down Expand Up @@ -186,6 +186,7 @@ By default it will generate next artifacts in `${outputDirectory} ` folder:
| `useResourcesAsWorkingDir` | :x: | `true` | Uses app resources folder as default working directory (always `true` on MacOS). |
| `version` | :x: | `${project.version}` | App version. |
| `vmArgs` | :x: | `[]` | VM arguments. |
| `appArgs` | :x: | `[]` | Additional arguments when launching the application. |

> [!IMPORTANT]
> Some default values depends on the used building tool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ public void setVmArgs(List<String> vmArgs) {
this.vmArgs = vmArgs;
}

@Input
@Optional
private List<String> appArgs;

public List<String> getAppArgs() {
return appArgs;
}

public void setAppArgs(List<String> appArgs) {
this.appArgs = appArgs;
}

@Input
@Optional
private WindowsConfig winConfig;
Expand Down Expand Up @@ -656,6 +668,7 @@ protected Packager createPackager() throws Exception {
.url(defaultIfNull(url, extension.getUrl()))
.version(defaultIfNull(version, extension.getVersion(), getProject().getVersion().toString()))
.vmArgs(defaultIfNull(vmArgs, extension.getVmArgs()))
.appArgs(defaultIfNull(appArgs, extension.getAppArgs()))
.winConfig(defaultIfNull(winConfig, extension.getWinConfig()));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ public class PackageMojo extends AbstractMojo {
*/
@Parameter(property = "vmArgs", required = false)
private List<String> vmArgs;

/**
* Additional arguments to provide to the application
*/
@Parameter(property = "appArgs", readonly = false)
private List<String> appArgs;

/**
* Provide your own runnable .jar (for example, a shaded .jar) instead of letting this plugin create one via
Expand Down Expand Up @@ -387,6 +393,7 @@ public void execute() throws MojoExecutionException {
.url(url)
.version(version)
.vmArgs(vmArgs)
.appArgs(appArgs)
.winConfig(winConfig);

// generate app, installers and bundles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PackagerSettings {
protected Platform platform;
protected String envPath;
protected List<String> vmArgs;
protected List<String> appArgs;
protected File runnableJar;
protected Boolean copyDependencies;
protected String jreDirectoryName;
Expand Down Expand Up @@ -279,6 +280,14 @@ public List<String> getVmArgs() {
return vmArgs;
}

/**
* Get application args
* @return Application args
*/
public List<String> getAppArgs() {
return appArgs;
}

/**
* Get runnable JAR
* @return Runnable JAR
Expand Down Expand Up @@ -685,6 +694,11 @@ public PackagerSettings vmArgs(List<String> vmArgs) {
return this;
}

public PackagerSettings appArgs(List<String> appArgs) {
this.appArgs = new ArrayList<>(appArgs);
return this;
}

/**
* Set runnable JAR
* @param runnableJar Runnable JAR
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/linux/startup.sh.vtl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#set ($vmArgs = $StringUtils.join($info.vmArgs, " "))
#set ($appArgs = $StringUtils.join($info.appArgs, " "))
#!/usr/bin/env bash
# GNU/Linux startup script generated by JavaPackager plugin

Expand Down Expand Up @@ -72,6 +73,8 @@ JVMClassPath="$BINARY"
JVMClassPath+=":${classpath}"
#end

AppArguments="${appArgs}"

#if ($info.useResourcesAsWorkingDir)
cd "$SCRIPTPATH"
#end
Expand All @@ -82,8 +85,8 @@ Bootstrap="$SCRIPTPATH/scripts/${info.bootstrapFile.name}" && [ -x "$Bootstrap"
#end

#if ($info.administratorRequired)
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY GDKBACKEND=x11 "${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
#else
"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" $@
"${JAVA}" ${JVMDefaultOptions} -jar "${JVMClassPath}" ${AppArguments} $@
#end
exit 0
8 changes: 8 additions & 0 deletions src/main/resources/mac/Info.plist.vtl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@
<false/>
#end
</dict>
#if ($info.appArgs)
<key>Arguments</key>
<array>
#foreach ($appArg in $info.appArgs)
<string>$appArg</string>
#end
</array>
#end
<key>LSEnvironment</key>
<dict>
#if ($info.bundleJre)
Expand Down