java - 如何使 exe 文件在命令行上写入文本?

标签 java maven cmd exe launch4j

我有java控制台应用程序,它将文本写入命令行。当我使用 jar 文件时,它工作得很好。但是当我创建 exe 文件并使用它时,应用程序不会将任何内容写入命令行。如果我在 cmd myapp.exe writeSomething > output.txt 中写入,我可以在 output.txt 中看到输出文本。我需要做什么才能 myapp.exe 开始将文本写入命令行?

我正在使用 launch4j-maven-plugin。

这是我的配置:

<plugin>
    <groupId>com.akathist.maven.plugins.launch4j</groupId>
    <artifactId>launch4j-maven-plugin</artifactId>
    <version>1.5.2</version>
    <executions>
        <execution>
            <id>l4j-clui</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>gui</headerType>
....

最佳答案

你的 POM 文件应该包含类似的内容

<plugin>
    <groupId>com.akathist.maven.plugins.launch4j</groupId>
    <artifactId>launch4j-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>l4j-clui</id>
            <phase>package</phase>
            <goals><goal>launch4j</goal></goals>    
            <configuration>
                <headerType>console</headerType> 
                ....
            </configuration>

线路<headerType>console</headerType>是关键。

因此它将生成 EXE 文件作为控制台应用程序,而不是 GUI 应用程序。

参见https://github.com/lukaszlenart/launch4j-maven-plugin了解更多详情。

关于java - 如何使 exe 文件在命令行上写入文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694275/

相关文章:

bash - mvn clean 在终端中运行良好,但在 cron 和 bash 文件中运行不正常

windows-7 - 列出具有指定名称的所有子目录

java - 带有 Oracle 连接的 Tomcat 数据源

java - hibernate 直到系统有空闲资源?低优先级任务调度

Ant 到 Maven - 多个构建目标

json - curl xput windows无法从文件读取数据

windows - 批处理文件: GOTO in a FOR loop

java - JSF View id 作为请求 token

java - 应用程序版本更新片段

java - 如何在 VSCode 中运行 Spring Boot maven 项目以及如何配置 spring boot web 应用程序的基本 url