Java – How to fix package names in IntelliJ


Is it possible to fix all the package names in a given folder in IntelliJ?

If files are manually imported into IntelliJ, and their package names are all wrong (including the sub-folders), how can I mass fix the package names?

This has caused me a lot of grief so far….

moving to a package or renaming a package

This has to be a bug.


If I am on a package in the project explorer, and rename the package, say it is:


Now I want to change this (and all the files under it) to:


I can't seem to do it!

When it says "rename package com.example.xml.xml to":

If I enter "com.example.xml" it won't work. I'm not sure what it is going on, I have spent a over an hour trying this as I have more files to import/fix.

Best Solution

It seems you can't change a full package name like this one: "com.example.xml.xml", but you can change each fragment, for that you can go to "View Options" (a little wheel) in the project view, disable "compact empty middle packages" options, and do something like renaming the second "xml" from the end, so the final package could get into something like:


Then you can drag and drop all contents in the last "xml" to "bar" package and finally delete the last "xml". In your case it seems you won't need to rename the package just move the contents