5

I'm using the codehaus jaxb2-maven-plugin, v1.5 to compile XSDs into POJOs, but the generated package name coerces the package name to lower case (so, if I have my target namespace as http://example.com/sampleNamespace, then the generated package is com.example.samplenamespace).

I've googled around a bit and found mostly people having problems with underscores getting munged to dots, and the solution for that, but I can't seem to find something specific for preserving the case of the namespace.

NB: I don't want to have to repeat myself and override the generated package name, so the generatePackage option in the maven config isn't for me.

Before finding about the underscore munging, I had tried that, and also a regular space - both stick a dot in there.

Any ideas?

Schema:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:t="http://example.com/sampleNamespace" targetNamespace="http://example.com/sampleNamespace"
jaxb:version="2.0">

    <complexType name="MyFirstClass">
        <sequence>
            <element name="MyFirstElement" type="string" />
        </sequence>
    </complexType>
</schema>

Maven config:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
</plugin>
2
  • 1
    Why do you want to preserve case in package. According to well accepted Java code conventions package names are always lower case, as described here? Oct 31, 2013 at 7:40
  • 1
    becauseihinkletusmakeitalllowercasemakesitveryhardtoread. If the answer is "It can't be done", then fine.
    – Phil
    Oct 31, 2013 at 7:49

1 Answer 1

1

You will need to leverage a JAXB bindings file to specify a package name if you do not want to use the one that JAXB generates based on common Java coding conversions.

<bindings 
  xmlns="http://java.sun.com/xml/ns/jaxb" 
  version="2.1">
  <bindings schemaLocation="schema.xsd">
    <schemaBindings>
      <package name="com.example.sampleNamespace"/>
    </schemaBindings>
  </bindings>
</bindings>
3
  • Isn't this just the same as the generatePackage option of the maven plugin, in that I still have to repeat myself? (Once in the schema namespace, once in a binding file / maven config)
    – Phil
    Oct 31, 2013 at 21:43
  • @Phil - I'm not sure what you mean about repeating yourself. You provide an override once regardless of which approach you use. Yes they are equivalent.
    – bdoughan
    Oct 31, 2013 at 21:52
  • 1
    That's the point - I don't want to have to provide an override. I want a simple config option that says to Jaxb "don't mangle the case". Or something like that. That way, I stick the configuration in a parent pom and not worry about what the namespace is this time, that time, every other time. Can it be done, without the duplication that is overriding the package name in some other file? The namespace (which I can't skip, can I?), converted, case preserved, is fine.
    – Phil
    Oct 31, 2013 at 21:55

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.