I have been trying to use JAXB with tomcat, but I have been have some
problems. I began trying to use the following class loader:
this.getClass().getClassLoader()
That didn't work. I don't actually understand much about those class
loader things. So I browsed the Internet for a solution and I found out
the following line:
Thread.currentThread().getContextClassLoader()
Then I plugged it into my JAXB initialization (br/sids/brh/jaxb is in
WEB-INF/class):
JAXBContext jc = JAXBContext.newInstance("br.sids.brh.jaxb",
Thread.currentThread().getContextClassLoader());
unmarshaller = jc.createUnmarshaller();
After some tomcat permissions tweaking I finally get that line working.
I was happy for a while, that is until I tried to actually get some
information from the XML. I used the following, very simple, just to
test it:
BoOcorrenciaPolicial bo = (BoOcorrenciaPolicial)
unmarshaller.unmarshal(new File(XML_DIR + id + ".xml"));
String hist = bo.getHIST();
Things didn't go as smoothly as I'd hope. This is the error I got:
java.lang.IllegalAccessError: Class
com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$FieldReflection can not
access a member of class br.sids.brh.jaxb.BoOcorrenciaPolicial with modifiers
"protected"
com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$FieldReflection.set(Accessor.java:204)
I noticed that "protected" modifiers seemed to be bothering tomcat. So
I thought I'd edit br/sids/brh/jaxb/BoOcorrenciaPolicial.java and
change all the occurences to "public". That seems to have done it. Even
<%= hist %> worked as expected. I was pleased, but I didn't like the
solution.
That file is automatically generated, it seems rather bad to me to edit
a automatically generated file like that. I'd have to notice any future
user that he has to do that (or call some script I could make) and
overall it doesn't seems really elegant to simple change protected to
public, whoever made the program probably had a reason to keep those
methods protected. Does anyone have a better solution? Maybe some
further tomcat configuration, the user of a different loader, perhaps.
---------------------------------------------------------------------
To start a new topic, e-mail: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]