How to import/open existing .java files in IntelliJ?

Viewed 1333

I'm still new to IntelliJ and still learning how to use it. Basically I have created a program already before and I just want to use my existing .java files in IntelliJ. I tried import/open option on the intro screen of IntelliJ but when I opened the .java files there weren't any menus, no functions, and you can't run the program at all, it just seemed to open a tabbed text editor of my .java files. So I tried creating a new project, and then opening the .java files afterwards, but no dice too, the run button is blacked out and I can't run my program. I used the command prompt before and used java (filename.java) to run my program and now just migrating to use an IDE. Can somebody help? I seem to have stuck at the beginning of my IDE journey.

2 Answers

You cannot simply open a file using Java. IntelliJ IDEA needs several configuration like Java SDK and other configuration files in order to run it. You have to create a simple Java project and copy your already created Java file into that project's src directory. Then you will be fine.

I just opened the first folder with '...web' as part of its name :) Not sure how scientific that was.

I am using Jet Brains Itellij Idea version with this info: IntelliJ IDEA 2021.2.3 (Community Edition) Build #IC-212.5457.46, built on October 12, 2021 Runtime version: 11.0.12+7-b1504.40 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1972M Cores: 4

Kotlin: 212-1.5.10-release-IJ5457.46

I drilled to a folder called detourweb. The app found what it needed.

Again, not sure how scientific or repeatable this method is. Assuming all developers will have some 'web' file in their project, try rolling the dice and drill to the first such file.

I don't expect a lot of up votes here, LOL. Here's an answer from a .Net Visual Studio dude.

Related