简体   繁体   English

配置IntelliJ IDEA为新项目创建主类

[英]Configuring IntelliJ IDEA to create main class for new projects

A friend is just starting to learn Java, using IntelliJ. 一个朋友刚刚开始使用IntelliJ学习Java。 He asks how can he set up some template so creating a new project will contain a default main class. 他问他如何设置一些模板,以便创建一个新项目将包含一个默认的主类。

Currently, when he creates a new project, it has no source files, and he has to add a Run/Debug application configuration manually, and then select the main class. 当前,当他创建一个新项目时,它没有源文件,并且他必须手动添加“运行/调试”应用程序配置,然后选择主类。

I don't know if Settings->File Templates is what you have in mind, but I'll point it out just in case. 我不知道您是否打算使用Settings-> File Templates,但是为了以防万一,我会指出来。

You can easily create a class and add a main method by typing "psvm " and filling in the method body. 通过键入“ psvm”并填写方法主体,可以轻松创建类并添加主要方法。 You run it by right clicking on the class and selecting "Run". 您可以通过右键单击该类并选择“运行”来运行它。 It's automatically be added to your Run/Config list, you just have to save it to make it permanent. 它会自动添加到您的“运行/配置”列表中,您只需要保存使其永久保存即可。

But my gut feeling is that IntelliJ has no such a feature for reading somebody's mind about a "default main class", nor should it. 但是我的直觉是IntelliJ没有这样的功能来读取人们关于“默认主类”的想法,也不应该。

在资源树中,右键单击要成为主类的类,然后在上下文菜单中应包含“为xyz创建主类”之类的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM