从使用 Inno Setup 和 maven 创建的本机 javafx 应用程序写入控制台 [英] Write to console from a native javafx app created with Inno Setup and maven

查看:29
本文介绍了从使用 Inno Setup 和 maven 创建的本机 javafx 应用程序写入控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a JavaFX app, and I am using the maven plugin javafx-maven-plugin to create an app bundle (app.exe in Windows, generated with Inno Setup).

当给出参数时,应用程序在控制台模式下运行.

The app runs in console mode when arguments are given.

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

The problem is that when running in console mode, I can't see the mesages printed to console. The messages (written with System.out.println) don't appear in the Windows console. But they are generated, because if I redirect the output to a file (app.exe > out.txt) the file contains all the messages.

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

I have tried to run the .exe with cygwin and even compiled the whole project in Linux, and in both of them the output is correctly displayed in the console. So the problem seems to be only when running the javafx exe with the Windows console (cmd). I guess the stdout is redirected to somewhere. How can I change this?

推荐答案

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

First of all: thanks for using the javafx-maven-plugin, I'm the maintainer of that maven-plugin.

简短版本:你不能做太多

长版:问题出在 JDK 的本机启动器上,与 InnoSetup 和 Maven 无关.

long version: The problem comes with the native launcher of the JDK and has nothing todo with InnoSetup, nor Maven.

引用 源代码本身 这是发生的事情:

Quoting the source-code itself this is what happens:

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.

在启动器里面挖了一下,如果找到了,其中检索 STD 输出,它被编译,因为 在windows系统上"USE_JLI_LAUNCH"未设置.真正的问题在于只附加那个控制台编写器 使用调试标志编译时

After digging a bit inside the launcher, if found the spot, 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 本身的错误/侥幸,我会尝试找到一些东西,并可能将其作为错误记录在 oracle-bug-tracker 上.

It might be a bug/fluke within the JDK itself, I'll try to find something and might file that as bug on oracle-bug-tracker.

经过进一步挖掘,我发现了一些有趣的东西:生成的 EXE 文件是一个简单的 windows 可执行文件,没有 cli 可执行文件 如在启动器源代码,这就是你没有看到任何控制台输出但在管道传输到某个文件时有结果的原因.

after some further digging, there is something I found interesting: the generated EXE-file is a simple windows-executable, no cli-executable as seen in the launcher-source-code, that is the reason you dont see any console-output but having the result when pipelining into some file.

解决方法:使用一些重定向创建/编译您自己的本地启动器文件,如下所述:

Workaround: create/compile your own native launcher-file using some redirects as described here:

将 cout 重定向到 Windows 中的控制台

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

这篇关于从使用 Inno Setup 和 maven 创建的本机 javafx 应用程序写入控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆