无法在IntelliJ中选择类作为主类 [英] Can't choose class as main class in IntelliJ

查看:2651
本文介绍了无法在IntelliJ中选择类作为主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IntelliJ中有一个Java项目,我刚刚在嵌套文件夹层次结构中添加了一堆文件。其中许多文件都是测试并包含main方法,因此我应该可以运行它们。但是我无法弄清楚如何做到这一点。

I have a Java project in IntelliJ to which I just added a bunch of files in a nested folder hierarchy. Many of these files are tests and include the main method, so I should be able to run them. However I cannot figure out how to do this.

我是IntelliJ的新手,之前的文件已经出现在项目层次结构中,并带有symbol ,对应于包含main()方法声明的Java类。但在这种情况下,它们会显示对应于源于源根目录的Java类的符号。

I'm new to IntelliJ and previously files have shown up in the project hierarchy with the symbol that corresponds to "Java class that contains declaration of the main() method." but in this scenario they show up with the symbol corresponding to "Java class located out of the source root."

那么如何编译和运行这些文件?

So how do I compile and run these files?

推荐答案

您链接的文档实际上在与源根目录之外的Java类关联的链接中有答案。
配置您的源和测试根,它应该可以工作。

The documentation you linked actually has the answer in the link associated with the "Java class located out of the source root." Configure your source and test roots and it should work.

https://www.jetbrains.com/idea/webhelp/configuring-content-roots.html

既然你声明这些测试你应该把它们标记为Test Source Root而不是Source Root。

Since you stated that these are tests you should probably go with them marked as Test Source Root instead of Source Root.

这篇关于无法在IntelliJ中选择类作为主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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