Our project uses XJC to generate Java classes from an XSD. I'm using JAVA EE 6.
When all the XSDs we have are re-generated, the generated classes include this comment at the top of the file:
// Generated on: 2011.02.23 at 02:17:06 PM GMT
Is it possible to suppress this comment? The reason is that we use SVN for version control, and every time we regenerate our classes, every single file shows as being changed in SVN, even though the only thing that differs is this comment. So I'd like to remove the comment altogether if possible.
There is a -no-header
directive, but I don't want to remove the entire header, so that future generations know that it's a file generated from a tool, and that modifications will be overwritten. I only want to remove the timestamp. (Or alternatively, I'd remove the inbuilt header and then insert my own header somehow.)
I also want to have text header with warning about classes was auto-generated and should not be modified manually, but because I place such files int git I do not want there always changed date of generation.
That header generated in com.sun.tools.xjc.Options#getPrologComment method. So essentially it call:
Messages.FILE_PROLOG_COMMENT
defined asDriver.FilePrologComment
. With futher debugging I found it use standard Java localization bundles.So, to change header format we just may provide our properties override for teir values from MessageBundle.properties.
We can do it in two way:
src/main/resources/com/sun/tools/xjc/MessageBundle.properties
in your project and change keyDriver.FilePrologComment
as you wish.XJC
dependency. So better I recommend place it assrc/main/resources/com/sun/tools/xjc/MessageBundle_en.properties
(note_en
suffix in filename) file and place there only properties you really want to change. Something like:Ensure that file in compiler classpath, especially if you call it from some plugins.
That is common mechanism for translation. See related answer: JAXB english comments in generated file
If you use ant, the following snippet may be useful for replacing the comments: