java 配置 IntelliJ IDEA 为新项目创建主类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/595130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring IntelliJ IDEA to create main class for new projects
提问by ripper234
A friend is just starting to learn Java, using IntelliJ. He asks how can he set up some template so creating a new project will contain a default main class.
一位朋友刚刚开始学习 Java,使用 IntelliJ。他问他如何设置一些模板,以便创建一个新项目将包含一个默认的主类。
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.
目前他新建项目时,没有源文件,需要手动添加一个Run/Debug应用配置,然后选择主类。
回答by duffymo
I don't know if Settings->File Templates is what you have in mind, but I'll point it out just in case.
我不知道“设置”->“文件模板”是否是您的想法,但我会指出以防万一。
You can easily create a class and add a main method by typing "psvm " and filling in the method body. 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.
您可以通过键入“psvm”并填写方法主体来轻松创建一个类并添加一个主要方法。您可以通过右键单击该类并选择“运行”来运行它。它会自动添加到您的运行/配置列表中,您只需保存它即可使其永久化。
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 没有这样的功能来读取某人对“默认主类”的想法,也不应该这样做。
回答by gibbon.cz
In the resources tree, right click on the class you want to be main and there should be item in the context menu like "Create main for xyz".
在资源树中,右键单击要成为主要的类,上下文菜单中应该有类似“为 xyz 创建主要”的项目。

