This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jaxb.properties file

 
itisha jain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to convert a java bean object into xml i.e marshalling.
However when i run my main program,it gives the error
"Exception in thread "main" javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package com"
How is this jaxb.properties file generated?
my code is as follows.i m able to see the address.xml file i.e being created bit it is empty.


package com;

import java.io.FileWriter;
import java.io.Writer;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

//import com.AddressBean;

public class AddressCreator {

public static void writeAddress(Writer pWriter) throws JAXBException {
// Create the element:

com.AddressBean addr = new com.AddressBean();
addr.setName("jane");
addr.setPostal("chandpur");

JAXBContext context = JAXBContext.newInstance("com");
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(addr, pWriter);
}

public static void main(String[] args) throws Exception {
FileWriter fw = new FileWriter("Address.xml");
writeAddress(fw);
fw.close();
}
}

Please help as I am stuck at this point.
itisha
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
 
Hans Woheel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having the same Exception problem, I put in JAXBContext.newInstance("com.abc.ccc", this.getClass().getClassLoader() ) and I still get the same Unable to locate jaxb.properties for package com.abc.ccc exception.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to make sure that jaxb.properties and bgm.ser files(which are generated by xjc tool) are under your "com" directory when you used JAXBContext.newInstance("com").

Thanks,
wise
 
Yogesh Gandhi
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear wise owen


my jaxb.properties and bgm.ser file are there in the classpath.
And also there in the folder that you have specified.

Can you please look at the following link :

http://www.coderanch.com/t/561676/XML/Unable-locate-jaxb-properties-package

And suggest, what I am doing wrong...


SOLUTION :
Got the soution to my problem...Actually it was required to give the classLoader as the second argument.
Use the overloaded method of newInstance.

Something of this sort




Source of the solution : http://www.jguru.com/forums/view.jsp?EID=1276852
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic