无法在IntelliJ中选择类作为主类

编程入门 行业动态 更新时间:2024-10-26 18:24:27
本文介绍了无法在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.

www.jetbrains/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中选择类作为主类

本文发布于:2023-11-25 05:53:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628583.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IntelliJ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!