180 }
181
182 public void writeCfgFile(Map<String, ? super Object> params,
183 File cfgFileName, String runtimeLocation) throws IOException {
184 cfgFileName.delete();
185
186 File mainJar = JLinkBundlerHelper.getMainJar(params);
187 ModFile.ModType mainJarType = ModFile.ModType.Unknown;
188
189 if (mainJar != null) {
190 mainJarType = new ModFile(mainJar).getModType();
191 }
192
193 String mainModule = StandardBundlerParam.MODULE.fetchFrom(params);
194
195 PrintStream out = new PrintStream(cfgFileName);
196
197 out.println("[Application]");
198 out.println("app.name=" + APP_NAME.fetchFrom(params));
199 out.println("app.version=" + VERSION.fetchFrom(params));
200 out.println("app.preferences.id=" + PREFERENCES_ID.fetchFrom(params));
201 out.println("app.runtime=" + runtimeLocation);
202 out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
203 out.println("app.classpath=" + String.join(File.pathSeparator,
204 CLASSPATH.fetchFrom(params).split("[ :;]")));
205
206 // The main app is required to be a jar, modular or unnamed.
207 if (mainModule != null &&
208 (mainJarType == ModFile.ModType.Unknown ||
209 mainJarType == ModFile.ModType.ModularJar)) {
210 out.println("app.mainmodule=" + mainModule);
211 } else {
212 String mainClass = JLinkBundlerHelper.getMainClass(params);
213 // If the app is contained in an unnamed jar then launch it the
214 // legacy way and the main class string must be
215 // of the format com/foo/Main
216 if (mainJar != null) {
217 out.println("app.mainjar="
218 + mainJar.toPath().getFileName().toString());
219 }
220 if (mainClass != null) {
221 out.println("app.mainclass="
222 + mainClass.replaceAll("\\.", "/"));
223 }
224 }
225
226 Integer port = JLinkBundlerHelper.DEBUG.fetchFrom(params);
227
228 if (port != null) {
229 out.println(
230 "app.debug=-agentlib:jdwp=transport=dt_socket,"
231 + "server=y,suspend=y,address=localhost:"
232 + port);
233 }
234
235 out.println();
236 out.println("[JavaOptions]");
237 List<String> jvmargs = JVM_OPTIONS.fetchFrom(params);
238 for (String arg : jvmargs) {
239 out.println(arg);
240 }
241 Path modsDir = getAppModsDir();
242 if (modsDir != null && modsDir.toFile().exists()) {
243 out.println("--module-path");
244 out.println(getAppDir().relativize(modsDir));
245 }
246
247 out.println();
248 out.println("[ArgOptions]");
249 List<String> args = ARGUMENTS.fetchFrom(params);
250 for (String arg : args) {
251 if (arg.endsWith("=") &&
252 (arg.indexOf("=") == arg.lastIndexOf("="))) {
253 out.print(arg.substring(0, arg.length() - 1));
254 out.println("\\=");
255 } else {
256 out.println(arg);
257 }
|
180 }
181
182 public void writeCfgFile(Map<String, ? super Object> params,
183 File cfgFileName, String runtimeLocation) throws IOException {
184 cfgFileName.delete();
185
186 File mainJar = JLinkBundlerHelper.getMainJar(params);
187 ModFile.ModType mainJarType = ModFile.ModType.Unknown;
188
189 if (mainJar != null) {
190 mainJarType = new ModFile(mainJar).getModType();
191 }
192
193 String mainModule = StandardBundlerParam.MODULE.fetchFrom(params);
194
195 PrintStream out = new PrintStream(cfgFileName);
196
197 out.println("[Application]");
198 out.println("app.name=" + APP_NAME.fetchFrom(params));
199 out.println("app.version=" + VERSION.fetchFrom(params));
200 out.println("app.runtime=" + runtimeLocation);
201 out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
202 out.println("app.classpath=" + String.join(File.pathSeparator,
203 CLASSPATH.fetchFrom(params).split("[ :;]")));
204
205 // The main app is required to be a jar, modular or unnamed.
206 if (mainModule != null &&
207 (mainJarType == ModFile.ModType.Unknown ||
208 mainJarType == ModFile.ModType.ModularJar)) {
209 out.println("app.mainmodule=" + mainModule);
210 } else {
211 String mainClass = JLinkBundlerHelper.getMainClass(params);
212 // If the app is contained in an unnamed jar then launch it the
213 // legacy way and the main class string must be
214 // of the format com/foo/Main
215 if (mainJar != null) {
216 out.println("app.mainjar="
217 + mainJar.toPath().getFileName().toString());
218 }
219 if (mainClass != null) {
220 out.println("app.mainclass="
221 + mainClass.replaceAll("\\.", "/"));
222 }
223 }
224
225 Integer port = JLinkBundlerHelper.DEBUG.fetchFrom(params);
226
227 if (port != null) {
228 out.println(
229 "app.debug=-agentlib:jdwp=transport=dt_socket,"
230 + "server=y,suspend=y,address=localhost:"
231 + port);
232 }
233
234 out.println();
235 out.println("[JavaOptions]");
236 List<String> jvmargs = JAVA_OPTIONS.fetchFrom(params);
237 for (String arg : jvmargs) {
238 out.println(arg);
239 }
240 Path modsDir = getAppModsDir();
241 if (modsDir != null && modsDir.toFile().exists()) {
242 out.println("--module-path");
243 out.println(getAppDir().relativize(modsDir));
244 }
245
246 out.println();
247 out.println("[ArgOptions]");
248 List<String> args = ARGUMENTS.fetchFrom(params);
249 for (String arg : args) {
250 if (arg.endsWith("=") &&
251 (arg.indexOf("=") == arg.lastIndexOf("="))) {
252 out.print(arg.substring(0, arg.length() - 1));
253 out.println("\\=");
254 } else {
255 out.println(arg);
256 }
|