从使用 Inno Setup 和 maven 创建的本机 javafx 应用程序写入控制台

Write to console from a native javafx app created with Inno Setup and maven

我有一个 JavaFX 应用程序,我正在使用 Maven 插件 javafx-maven-plugin 创建一个应用程序包(app.exe in Windows,使用 Inno Setup 生成)。

当给出参数时,应用程序 运行 处于控制台模式。

问题是当 运行在控制台模式下,我看不到打印到控制台的消息。消息(用 System.out.println 编写)不会出现在 Windows 控制台中。但是它们是生成的,因为如果我将输出重定向到一个文件 (app.exe > out.txt),该文件包含所有消息。

我已经尝试 运行 使用 cygwin 的 .exe,甚至在 Linux 中编译了整个项目,并且在它们中,输出都正确显示在控制台中。所以问题似乎只出现在 运行 使用 Windows 控制台 (cmd) 运行 javafx exe 时。我猜标准输出被重定向到某个地方。我该如何更改?

首先:感谢您使用javafx-maven-plugin,我是维护者那个maven-plugin.

简短版:你不能做很多事情

长版: 该问题与 JDK 的本机启动器有关,与 InnoSetup 或 Maven 无关。

引用 the source-code itself 是这样的:

Basic approach:
  - Launcher executable loads packager.dll/libpackager.dylib/libpackager.so and calls start_launcher below.
  - Reads app/package.cfg or Info.plist or app/<appname>.cfg for application launch configuration
     (package.cfg is property file).
  - Load JVM with requested JVM settings (bundled client JVM if availble, server or installed JVM otherwise).
  - Wait for JVM to exit and then exit from Main
  - To debug application by set env variable (TODO) or pass "/Debug" option on command line.
  - TODO: default directory is set to user's Documents and Settings.
  - Application folder is added to the library path (so LoadLibrary()) works.

在发射器内部挖一点后,如果找到那个地方,where the STD-output is retrieved, which gets compiled, because on windows-systems "USE_JLI_LAUNCH" is not set. The real problem with this comes with the condition to only append that console-writer when being compiled with DEBUG-flag

它可能是 JDK 本身中的一个 bug/fluke,我会尝试找到一些东西,并可能将其作为错误记录在 oracle-bug-tracker 上。

编辑: 经过进一步挖掘,我发现了一些有趣的东西:生成的 EXE 文件是一个简单的 windows 可执行文件,没有 cli 可执行文件 as seen in the launcher-source-code,这就是你看不到任何控制台输出但在流水线化到某个文件时得到结果的原因。

解决方法: create/compile 您自己的本机启动器文件使用此处所述的一些重定向:

Redirecting cout to a console in windows

https://bobobobo.wordpress.com/2009/03/01/how-to-attach-a-console-to-your-gui-app-in-c/