Search code examples
javaeclipsejavafxpackagemove

Move a package to another package and also update string references?


I'm using Eclipse IDE and i have following file structure:

/app
/res
/res/assets
/res/views/FXML/...(fxml files)
.....

I want to move the /res package to the package /app.

There is a Move... button in the Refactor context menu but it doesn't allow me to move a package to another one in the same project. Eclipse provides a feature to rename a package and also update the string paths. People were suggesting to rename the package too in the answers of other similar questions. But the problem i faced is a bit different:

I tried to rename the package res to app.res as Eclipse uses dot (.) as a path separator. But when eclipse updates a string path it uses dot(.) again. For example:

before: String view_file = "/res/views/FXML/BaseUI.fxml";
after updating: String view_file = "/app.res/views/FXML/BaseUI.fxml";
what i need: String view_file = "/app/res/views/FXML/BaseUI.fxml";

and dot(.) is not valid for paths. I also tried using / instead of dot(.) but didn't work. Well i could change the path manually but there are a lot of paths to update so it'll be time consuming.

So how can i accomplish this?

Any help will be appreciated :)


Solution

  • A possible workaround would be to replace all the paths using editors like VS Code, Sublime etc after moving the package manually.

    In your case, the process would be like this, using VS Code:

    1. Move the package /res to /app manually
    2. Now open the project folder with VS Code
    3. Go to Search sidebar
    4. Search for /res/views/FXML/BaseUI.fxml
    5. Enter /app/res/views/FXML/BaseUI.fxml in the Replace input box
    6. Click on the Replace All button

    This post might be helpful for the replacing task.

    Hope it helps :)