The Package Migration tool does not seem to convert all source code package references in the project.

By: Christopher Moeller

Abstract: The Package Migration tool is not a refactoring tool.

Question:

After using the Package Migration tool (Tools | Package Migration... | New) to migrate all com.foo.* into com.foo.sub.*, the project fails to compile and produces the following error:

"Test.java": Error #: 901 : package com.foo stated in source D:/java/source/Package_Migration_Test/src/com/foo/sub/Test.java does not match directory com.foo.sub at line 1, column 22

 

Answer:

Important: The best way to convert from one package structure to another is to use refactoring, as this will ensure that each and every reference in the project reflects the change. Refactoring in JBuilder also allows the user to review what changes will be made before commiting. To do this, simply double-click on the desired package in the Project Pane, and then choose the UML tab in the Editor. When the object view is shown, right-click on the package reference and choose "Rename Package <package name>...," in the dialog that appears, type the new name for the package. By default, JBuilder will show a list of intended changes in the Message Pane. Click on the Refactoring Cube button to commit the listed changes.

Now specifically, the error in the above example is being thrown because the package statement in the source file had not been modified to reflect the new package directory structure:

// Should be: package com.foo.sub.*;

package com.foo.*;

public class Test
{
public Test() { }
}

In this case, it would be necessary to manually edit the package statement in the source file to the correct delineation.


Server Response from: ETNASC04