JAXB XJC Possible to suppress comment creation in generated classes?

Matt picture Matt · Feb 23, 2011 · Viewed 10.4k times · Source

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.)

Answer

cata picture cata · Aug 23, 2011

I am using this Maven plugin which replaces the // Generated on: 2011.02.23 at 02:17:06 PM GMT line:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <version>1.3.8</version>
    <executions>
        <execution> 
            <phase>prepare-package</phase>                          
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>                         
        <includes>                              
            <include>src/main/java/jaxb/*.java</include>            
        </includes>
        <token>^// Generated on.*$</token>
        <value>// Generated on: [TEXT REMOVED by maven-replacer-plugin]</value>                         
        <regexFlags>
            <regexFlag>MULTILINE</regexFlag>
        </regexFlags>
    </configuration>
</plugin>