woodStone
woodStone

Reputation: 147

Java: How to move classes to another package in Idea Intellij?

I have the following file sctructure:

name1/name2/name3/name4 (must be project's root and git root)/src/main/java/com/fileinside1/fileinside2/fileinside3/init/woodenStone

Inside the last folder (woodenStone) my .java files are located.

The IntelliJ Idea makes everything look like this:

name4
  src
     main.java.com.fileinside1.fileinside2.fileinside3                             
               init.woodenStone
                      SomeFile1.java
                      SomeFile2.java

And inside every file there is a

package main/java/com/fileinside1/fileinside2/fileinside3/init/woodenStone;

as the first line.

So, the files are located in package which starts with main folder. But I need the package to be

com/fileinside1/fileinside2/fileinside3/init/woodenStone,

to get a little deeper inside.

So far I only manage to do so by manually changing the package name in .java files, Alt+Entering it and selecting "Move to package com/fileinside1/fileinside2/fileinside3/init/woodenStone".

But I have more than 50 files and would really appreciate a way to do it for all files at once.

Could anyone please tell me if there is such a way?

EDIT: Just found out that even the way I use doesn't really work right. Instead of moving file's into deeer project's folder, Idea just creates a second com folder inside src (How does it even manage to create a floder with the same name?).

Upvotes: 3

Views: 10190

Answers (1)

teppic
teppic

Reputation: 7286

  • Open the Project panel and select the Project view (top left).

  • Make sure that the main directory isn't marked as a source root. You may need to unmark it by right clicking and selecting Mark Directory As -> Unmark...)

  • Make sure that your java directory is marked as a source root (right click, Mark Directory As -> Sources Root).

  • Select all the files in the woodenStone directory.

  • F6 -> Move Specified Files -> to package

Upvotes: 6

Related Questions