使用外部端子 [英] Use external terminal

查看:93
本文介绍了使用外部端子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让Netbeans在系统终端而不是其内置终端中运行Java项目?

How can I have Netbeans run my Java project inside a system terminal rather than its built-in terminal?

我环顾四周,显然我应该这样做Project Properties->Run->Console Type,但是很遗憾,在历史上的某个时候,它已从项目配置面板中删除.

I looked around and apparently I am supposed to do Project Properties->Run->Console Type but this has regrettably been removed from the project configuration panel at some point in history.

关于这个问题,我可以在互联网上找到的其他所有线程都有-可以预期-没有答复.

Every other thread I can dig up on the internet regarding this issue has - predictably - no replies.

我知道我可以从命令行运行jar文件,但是集成的解决方案会有所帮助.

I know I can run the jar file from the command-line but an integrated solution would be helpful.

我正在使用Netbeans 7.

I am using Netbeans 7.

推荐答案

我不确定可以对Ant项目执行此操作,但是对于Maven项目可以做到.

I am not sure this can be done for an Ant project but it can be done for a Maven project.

  • 创建一个Maven项目.文件->新项目.选择类别"Maven"和项目类型"Java应用程序".单击下一步,然后单击完成以接受项目默认值.
  • 添加具有公共静态void main(String args [])方法的Main类.在项目"窗口中展开源包".选择任何包.右键单击->新建->"Java类".

在退出前添加一些内容以等待输出,否则您的终端将退出,而您没有时间查看输出.

Add something to wait for output before exiting or your terminal will exit without your having time to view the output.

public static void main(String[] args) {
    System.out.println("hello");
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
        br.readLine();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

  • 在项目"窗口中选择项目.右键单击以弹出.选择属性.选择类别运行".单击Main class旁边的Browse按钮,然后选择Main class.
  • 使用工具栏上的绿色三角形,运行->运行项目或F6,正常运行项目一次.
  • 在项目窗口中展开项目文件"节点.双击"nbactions.xml".
  • 更改运行"操作的属性.将可执行文件更改为您的终端,并在参数中添加适当的标志和Java.
    • Select the project in the projects window. Right-click for pop-up. Choose Properties. Select category "Run". Click the Browse button next to Main class and select the Main class.
    • Run the project one time normally with the green triangle on the toolbar, menu Run-> Run Project or F6.
    • Expland the "Project Files" node in the projects window. Double-click "nbactions.xml".
    • Change the Properties for the "run" action. Change executable to your terminal and add the appropriate flags and java to the arguments.
    • 例如来自:

              <properties>
                  <exec.args>-classpath %classpath wshackle.mavenproject2.Main</exec.args>
                  <exec.executable>java</exec.executable>
              </properties>
      

      至:

              <properties>
                  <exec.args>-x java -classpath %classpath wshackle.mavenproject2.Main</exec.args>
                  <exec.executable>gnome-terminal</exec.executable>
              </properties>
      

      或对于Windows:

      or for Windows:

              <properties>
                  <exec.args>/c java -classpath %classpath wshackle.mavenproject2.Main</exec.args>
                  <exec.executable>cmd</exec.executable>
              </properties>
      

      • 保存并关闭此文件.
      • 运行项目.现在,它应该在外部终端中打开.
      • 注意:我在这里提供了相同的答案: 在命令行上显示netbeans java输出终端

        Note: I provided the same answer here: display netbeans java output terminal on the command line

        这篇关于使用外部端子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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