Reputation: 1775
I am using JAXB version 2. I am using the Sun version so that I can use the replacement of namespaces that is not functioning with standard implementation. This all works fine when my classes are in the same package of the application and the jaxb.properties file is sitting in with the model classes.
When I move these all to a separate lib, a jar file, then the namespace replacing fails to function and all namespaces continue to be ns1 on a marshal. So to me it looks like it is not picking up the context factory definition defined in my jaxb.properties file and defaulting to the standard Java version.
There is not jaxb.properties not found exception thrown.
Any idea what might be going on or how to fix it?. Thanks for reading.
Upvotes: 2
Views: 7161
Reputation: 1775
As it goes it was a problem with my JAR file. I had copied the package-info.java over to my JAR in the build but not copied the compiled package-info.class.
Including both the package-info.java and .class has solved the issue.
Thanks for reading and thanks very much for the replies.
Upvotes: 2
Reputation: 149037
Your Setup
When I move these all to a separate lib, a jar file, then the namespace replacing fails to function and all namespaces continue to be ns1 on a marshal.
In this setup you have the model classes and the jaxb.properties
in the same jar file? You will need to ensure that the jaxb.properties still be in the same package as your model classes:
There is not jaxb.properties not found exception thrown.
Is your jaxb.properties being found?
There is no exception thrown when a jaxb.properties file is not present, since the JAXB runtime will just default to a JAXB impl (either the RI, or one define via the META-INF/services
mechanism. You could test if it is finding your jaxb.properties file by but an invalid JAXBContextFactory entry, this would create an exception like:
javax.xml.bind.context.factory=INVALID_ENTRY
would cause the following exception:
Exception in thread "main" javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: INVALID_ENTRY]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:187)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:331)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at forum22.Demo.main(Demo.java:10)
Caused by: java.lang.ClassNotFoundException: INVALID_ENTRY
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:481)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:185)
... 4 more
Upvotes: 3
Reputation: 32427
Have you tried putting it in the META-INF/services
directory in the jar file?
Upvotes: 1