本文介绍了在命令行上显示netbeans java输出终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将NetBeans ide Java程序控制台输出显示到Windows命令行输出?请帮忙,因为我是新来的...提前感谢在这里,我必须从NetBeans执行程序,但只有输出必须显示在Windows命令行上.
How to display the NetBeans ide java program console output onto the windows command line output? please help as I am new to this...thanks in advancehere I must execute the program from NetBeans but only the output must be displayed on my windows command line.
推荐答案
我不确定可以对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输出终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!