iamlearningmath
iamlearningmath

Reputation: 31

Running Java file in IntelliJ

I need some help with IntelliJ. I am fairly new to programming, and I have some experience with the IDE but I am by no means a know-it-all when it comes to IntelliJ.

I have 3 Java files (without their respective class files). When I open intelliJ it asks me:

I click on open, IntelliJ opens up a file location, I click on one of the three Java files to open, and I drag the other two one by one (they open in their separate tab).

I cannot figure out how to run them. It is likely that I need to create run configuration and I don't know how to do it. I know how to create a new project and get everything working, but I don't know how I can get the files working if I just open them. Can someone tell me how to create the run configurations to run the files? Please and thank you.

Upvotes: 2

Views: 6680

Answers (2)

iamlearningmath
iamlearningmath

Reputation: 31

Folders have to be marked as source root. Right click the project directory, and scroll down to Mark Directory As, and then select Source Root. Solved the problem for me.

Upvotes: 0

Igor Kanshyn
Igor Kanshyn

Reputation: 912

IntelliJ IDEA is a great IDE!

This is what I would do:

  • Select File/New/Project... in the menu. You will get a new modal window.
  • Then select Java on the left, make sure that you have your JDK selected (top right), it not there, create it right from the window. Click 'Next'.
  • Just go 'Next' on the 'create project from template' step.
  • Then type your project name and select a folder for it. It will create a new project.
  • After that, copy your java files into /src folder using drag-and-drop in IDEA or just a file manager you like. Now you have an IDEA project with your source code in it. You might need to sync your IDEA project, use File/Synchronize for that.
  • Finally, you can right click on you java file and 'Run' it from IDEA.

It the project fails on compilation you might need to add required imports and libraries, but that depends on your code. IDEA will highlight all the errors.

Upvotes: 2

Related Questions