• Post Reply Bookmark Topic Watch Topic
  • New Topic

relearning jaxb  RSS feed

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a victim of my own lack of code comments. A couple of years ago I wrote an application to consume the weather conditions and forecast from NOAA and add it to our intranet home page. Now I want to make some changes to it (I want to add weather alerts) and I'll be damned if I can remember how I created this thing. Many of the classes contain this notice:
This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6

So is the xjc compiler run each time I build in Netbeans or does it have to be run outside of the IDE environment?

I'm kicking myself for not taking notes on this when I built it the first time. I feel really dumb that I have to learn this all over again.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is driving me crazy. I'm re-writing the whole thing to figure out how I wrote it in the first place. I've created a simple web application to just get the current weather conditions but I'm getting a JAXBException on the unmarshal line.
First, here's the first section of the .xsd file that I'm working from:

Here's the critical part of the object generated:

Here's the code from a context listener on our production server. This code works.

Here's the code from my new app. This does not work.

It throws this error: There is an underscore in "current_observation", the code formatter is hiding it

This is the XML that it's trying to parse:


The root element looks correct. I don't understand why it's expecting something else or why the code in the context listener works, but the code in the servlet does not. What the heck is going on here?
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This problem seems a lot like this problem Have you tried the same solution?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That does look very similar. I'll dig into that and try those suggestions, although that will still leave me puzzled as to why the production code is working.

Thanks!
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried those suggestions...no joy. Back to the drawing board.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I don't like to depend on IDEs to build stuff. Too much of the build process is either in a particular version of a particular IDE (discontinued 3 years ago) or in the motions you go through to use it. If you'd augmented your IDE with an Ant script, you could likely still run that script. If you'd made it a Maven project, you'd almost certainly be able to do a build. Not only you, but anyone on the planet you handed it to.

You're not going to pry my IDE away from me, but all my projects can be built offline on a non-gui machine. Of course, I'm also running Jenkins these days, which is another good incentive.

JAXB gives me ulcers. It's never as easy to work with as it ought to be and it's probably mostly just poor and conflicting documentation - obsolete docs live forever on the Internet and often show up in searches ahead of the current stuff. JSF used to give me fits because of that.

What you might want to do is investigate Apache CXF. It's a nice annotation-based facility that does both ReST and SOAP (IIRC). It's very easy to deal with once you get the basics down - the processors are all simply annotated POJOs. Which not only makes coding more fun, it makes it easier to write offline tests via jUnit or one of its friends.

And it's easy to incorporate into a Maven build

 
g tsuji
Ranch Hand
Posts: 697
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What I would look into is why and where the namespace urn:oasis:names:tc:emergency:cap:1.2 slipped in. The xsd as quoted contains no namespace. If it is being compiled as such, "unexpected element" should be the one expected (if no further customization is involved in the xjc.) One of the lead is also that there is a processing-instruction xml-stylesheet emitted. For the unmarshaller, it is not a "live" instruction and it won't be recognized. Even if it is "live" somewhere in the flow, the worst is that it changes the namespace to the one shown and the JAXBExcept should mention this only in the fashion reversed, expected element becoming unexcepted and the expected element unexpected.) Those are the places I would look into in the first instance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!