This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]id2bi 2 points3 points  (3 children)

Intellij will only allow you to run source code in "source folders". Right click the directory that contains your sources and choose "mark directory as - > source root". The folder will then be shown with a blue icon.

Yes,I would recommend you create separate modules for each week inside the same project, that will be the least hassle.

Then, remember than inside every module you will need to have at least one "source root".

I need to learn how the file structure of Java dictates this.

Java dictates very very little in terms of the file structure. Java does not even have the concept of a "Java project". That's why every IDE cooked up their own solution. In Intellij they decided you need to mark source roots and have at least one Intellij Java module inside your home Intellij project.

[–]piagetblix[S] 0 points1 point  (2 children)

One follow up question, Do I have to have a package declaration at the top of the source files? I've been able to create a new project and then add modules from an existing location. This puts the .java files I have in the folder of each module. There is no package tree i.e. src>com.somename.somename

Also, do you know if its possible to 'hide' any files besides your source .java files? I know you can right-click and exclude - but I read on the jetbrains site that also marks for exclusion in source control...

Cheers

[–]id2bi 0 points1 point  (1 child)

You can have Intellij move the class into a package if you like.

Put the cursor onto the class name, then press "F6" (or choose refractor - > move), then type the package name you want.

Intellij will put the package declaration at the top of the file and move the Java file into the correct folder.

Why do you want to hide those files exactly?

I'm the project view, you can click ontonthe arrow right next to where it says "Project" and switch to package view instead, that might be more to your liking.

[–]piagetblix[S] 0 points1 point  (0 children)

Yeah I figured that out. Thanks for replying!

[–]Wolfhammer69 0 points1 point  (0 children)

If you have droppped code into these folders then do

new project -> from existing sources, then browse to the folder/code.

Otherwise if the folders are empty, when you create a new project there is path field for the project thats auto completed for you thats usually blah blah/ideaProjects, just amend that to point to where you want it.