如何在Mac上禁用控制台启动Java应用程序

时间:2014-11-30 08:32:02

标签: java macos console

我已经在JAVA中编写了一个应用程序,我已经通过launchctl(基本上是cron)安装了它。

我遇到的问题是每次工作开始时,我都会简单地看到" Java"在菜单栏和键盘控制被带离我(再次短暂但足以惹恼)。

如何阻止应用程序执行此操作?在launchctl中有什么我可以做的吗?我知道还有其他应用程序启动时,不会表现出这种行为。

1 个答案:

答案 0 :(得分:0)

问题不在于Mac或LaunchCtl。问题与我在应用程序中安装的某些JavaFX有关。包含“main”的类由javafx.application.Application扩展。在我没有启动UI的情况下(它也可以运行无头)因为JavaFX“应用程序”无论如何都要接管。

决议是创建另一个扩展“Application”的类。当我需要UI启动时,我只实例化并运行该类。

这是应用程序的主要

在 公共类MyApp        扩展申请{

  @Override
  public void start(Stage primaryStage)
          throws IOException {
  ...
  }

  public static void main(String[] args)
          throws Exception {
    UIMain uiMain;
    uiMain = new UIMain();

    if (args.length == 0) {
      uiMain.run(args);
    } else {
    // Even though there is no UI being launched it still popped "Java" in the toolbar here
...
    }
  }
}

之后(可能有更好的方法)

public class MyApp {

  public static void main(String[] args)
          throws Exception {
    UIMain uiMain;
    uiMain = new UIMain();

    if (args.length == 0) {
      uiMain.run(args);
    } else {
    // When this section runs I don't get the annoying Java pop in the Toolbar
... 
    }
}
public class UIMain
        extends Application {

  @Override
  public void start(Stage primaryStage)
          throws IOException {
...
  }

  public void run(String[] args) {
    launch(args);
  }

}