5

I've build a war file from my web application using NetBeans 7.2 (in Windows 7 environment!), which runs correctly during test phase with GlassFish 3.1.2 server within NetBeans context.

The defined namespace within the package-info.java file is correctly added to my xml file.

However when I deploy the war file in a seperatetely running GlassFish server on a Linux machine the namespace is set to the default ns1 and NOT to the one defined by the package-info.java file?

What am I doing wrong?

Regards, Gerard

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
g.verhaag
  • 139
  • 3
  • 11

1 Answers1

5

Why is JAXB namespace of my xml set to default ns1?

ns1 is not the namespace but the prefix. The prefix is not significant. For example the following documents are all equivalent. The foo element is in the FOO namespace, and the bar element is in the BAR namespace.

<a:foo xmlns:a="FOO" xmlns:b="BAR>
    <b:bar>Hello World</b:bar>
</a:foo>
<ns1:foo xmlns:ns1="FOO" xmlns:ns2="BAR>
    <ns2:bar>Hello World</ns2:bar>
</ns1:foo>
<foo xmlns="FOO" xmlns:b="BAR>
    <b:bar>Hello World</b:bar>
</foo>

What am I doing wrong?

Nothing. A JAXB (JSR-222) implementation is not required to use the prefix specified in the @XmlSchema annotation. EclipseLink JAXB (MOXy) does and recent versions of the JAXB RI appear to. The version/implementation of JAXB in NetBeans 7.2 appears to, while the version/implementation of JAXB that GlassFish 3.1.2 uses does not.

Below is a link to an article that I wrote that goes into a little more detail and covers the NamespacePrefixMapper extension that may be useful here.

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Thanks for your answer, but still I don't understand why my prefix is added correctly when running the application within Netbeans, and NOT on a seperate GlassFish server? – g.verhaag Jan 29 '13 at 10:52
  • @user2020967 - It's probably a different implementation or version of JAXB (JSR-222) between those environments. – bdoughan Jan 29 '13 at 10:57
  • @user2020967 - The prefixes are correct in both environments since they represent the same namespace qualification as mapped in your model. The link at the end of my answer contains techniques that you can use to control which prefix is used. – bdoughan Jan 29 '13 at 11:47
  • Sorry, but I'm afraid I don't understand it anymore. Why is my prefix in the NetBeans environment equal to that set in the package-info.java file, and equal to ns1 in case of the standalone GlassFish run? – g.verhaag Jan 29 '13 at 12:24
  • @user2020967 - JAXB (JSR-222) implementations are not required to use the prefixes specified in the `@XmlSchema` annotation. Prefixes themselves aren't significant do this is ok. Since you are seeing different behaviour each environment is using a different version/implementation of JAXB. – bdoughan Jan 29 '13 at 13:11
  • Blaise, thanks for your effort to explain it to me, but I'm afraid I don't understand it, sorry!! – g.verhaag Jan 29 '13 at 15:09
  • @user2020967 - As I don't know how familiar you are with XML, do you understand that as far as an XML parser is concerned the 3 XML documents I have included in my answer have the exact same namespace qualification? – bdoughan Jan 29 '13 at 15:14
  • Yes, the simularity between the 3 examples is clear! But I'd like to change the ns1 prefix to the one used when running the application from within NetBeans? Maybe, I'd start with the basics again! – g.verhaag Jan 29 '13 at 16:20
  • @user2020967 - Then it comes down to the fact that a JAXB (JSR-222) implementation is not required to use the prefix specified in the `@XmlSchema` annotation. The fact that it works in one environment (NetBeans 7.2) and not another (GlassFish 3.1.2) indicates that a different version/implementation of JAXB is used in the two environments. Here is a link to an article I wrote about influencing the prefix used: http://blog.bdoughan.com/2011/11/jaxb-and-namespace-prefixes.html – bdoughan Jan 29 '13 at 16:26
  • I went through your document, but to be honest, it wasn't much of a help, sorry. Perhaps this indicates that I lack a thorough background when it comes to this matter! By the way in NetBeans I also use the GlassFish 3.1.2 server! – g.verhaag Jan 29 '13 at 16:47