Regenerating .java file from a .form file
By karthikr on Jul 26, 2008
Case 1: Sometimes a .java file associated with a .form file in an IDE project gets deleted or lost. In such cases, when the project is opened in the ide, .form file is shown in the navigator. Opening the .form file will not open the GUI Designer but will open the .form file as a text file. This is because the GUI Designer needs both the .java file and the .form file.
Case 2: Another variant of this problem is when the
.java file is not lost but has gone out of sync with the .form file. In
such cases any changes made to the .form file will not be reflected in
the .java file.
The following provides a solution to the above issue.
- Make a backup of both .form and .java file to a safe place. It is important to make a backup to go back to at least the initial erroneous state.
- For case 2 alone: first check the [userdir]/var/log/messages.log file and check out the error messages. Quite a few times, the problem happens because of a simple error in the generated file (like //BEGIN_ statements in the source file being corrupted). The error messages and/or stacktraces can sometimes provide a clue as to where the corruption happened and the error can be manually corrected by opening the .java file in an external editor. In cases of simple errors, this may solve the issue. If not...
- Close the ide.
- Delete both .java and .form from the project directory.
- Restart the ide.
- Open the project.
- Create a new form (with the same name as the original corrupted form file) in the same package it existed before.
- Close the ide.
- Copy the .form file from the backup to the project directory (overwriting the form created in the previous step).
- Restart the ide, open the project and open the form in the GUI editor.
- Make a simple change (like setting resizable to false). The .java file now should be regenerated by the ide to be in sync with the .form file.
- Reverse the change made in the previous step( i.e set resizable back to true).