简体   繁体   English

如何设置Intellij,这样当我打开一个类时,无论在什么目录下它都可以正常运行?

[英]How to set up Intellij so when I open a class it can run properly no matter the directory?

I'm a Java beginner and came from JGrasp where I could simply open up a class anywhere and be able to run it without any problems. 我是Java的初学者,来自JGrasp,我可以在任何地方打开一个类并能够毫无问题地运行它。 When I open a class in Intellij it says the configuration isn't correct. 当我在Intellij中打开一个类时,它说配置不正确。 Is there a way to set up Intellij by default to automatically set up the SDK for everything to default and allow me to open up any class without setting up configuration for each one. 有没有一种方法可以默认设置Intellij,以自动将所有默认设置的SDK设置为默认设置,并允许我打开任何类而无需为每个类设置配置。 I attached an image that shows the edit configuration popup for a directory I opened. 我附加了一个图像,该图像显示了我打开的目录的编辑配置弹出窗口。 I am aware how to set up a project from scratch but I'd like to be able to open up code from anywhere without too much hassle setting up SDKs and configurations every time. 我知道如何从头开始建立项目,但是我希望能够从任何地方打开代码,而不必每次都麻烦地设置SDK和配置。

Here is the code : 这是代码: 在此处输入图片说明

To be able to run a class, you first need that class to have a "psvm" ( public static void main , which can be easily generated for you by simply writing "psvm" when you're coding a new method in a class). 为了能够运行一个类,您首先需要使该类具有一个“ psvm”( public static void main ,当您在一个类中编码新方法时,只需编写“ psvm”就可以轻松为您生成) 。

Once that's done, you head over to the left, in your project's folder-tree, right-click your class, and press the "Run" button. 完成后,您将转到项目文件夹树中的左侧,右键单击您的类,然后按“运行”按钮。

项目的文件夹树

The green arrow on top of the class' blue circle indicates that this class has a "psvm" and that you thus can "Run" it. 该类的蓝色圆圈上方的绿色箭头表示该类具有“ psvm”,因此可以“运行”它。

psvm指示器

After having done this once, IntelliJ will remember that you have ran this class and the "Edit confirguration" dropdown should usually always allow you to select it. 完成一次此操作后,IntelliJ将记住您已经运行了该类,并且“编辑配置”下拉列表通常应始终允许您选择它。 Once the class you want to Run from that dropdown is selected, you can simply press the green triangle next to it. 一旦选择了要从该下拉菜单中运行的班级,您只需按一下其旁边的绿色三角形即可。

更快的第二次访问

您应将源代码(即扩展名为.java的文件)放置到一个单独的目录(与已编译的类(即扩展名为.class的文件)​​),并将其设置为IDEA中的源根目录:右键单击哪个服务器作为根软件包目录,然后选择->标记为->源根。

暂无
暂无

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

相关问题 如何正确设置此端点? - How can I properly set up this endpoint? 如何在不同的目录中编译和运行 Java 类? - How can I compile and run a Java class in a different directory? 如何设置Intellij复制资源目录,而不仅仅是目录内容? - How can I set Intellij to copy resource directories and not just the directory content? 如何设置Zk会话(org.zkoss.zk.ui),以便可以对扩展GenericForwardComposer的控制器类进行单元测试 - How can I set up Zk Sessions (org.zkoss.zk.ui) so I can unit test a controller class extending GenericForwardComposer 当我单击 .java 文件时,IntelliJ 不会将其作为类打开 - When I click a .java file, IntelliJ doesn't open it as a class 如何绑定2个Java文件,以便在运行jar文件时它们都可以打开 - How do I bind 2 java files so they both open when I run the jar file 如何在mac上的intellij 9中设置jdk - how can i set the jdk in intellij 9 on mac 如何设置此功能,以便在单击按钮时数字选​​择器中的值发生变化,反之亦然? - How can I set this up so that if I click on a button, the value changes in a number picker and vice versa? 我是否正确设置了此 BST? 如果是这样,我该如何在其他方法中使用它? - Did I set up this BST correctly? If so, how can I use it in other methods? 如何正确重写Runnable.run(),以便它可以接受参数? - How to properly override Runnable.run(), so it can take parameters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM