File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark " file" Watch " file" New topic
Author file

itisha jain

Joined: Oct 04, 2005
Posts: 11

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 for package com"
How is this 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 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();

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");

Please help as I am stuck at this point.
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
Check this link...Why am I seeing "Unable to locate for package aaa.bbb.ccc."?

Spritle Software Blogs
Hans Woheel

Joined: Jan 12, 2006
Posts: 5
I'm having the same Exception problem, I put in JAXBContext.newInstance("", this.getClass().getClassLoader() ) and I still get the same Unable to locate for package exception.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
You need to make sure that and bgm.ser files(which are generated by xjc tool) are under your "com" directory when you used JAXBContext.newInstance("com").

Yogesh Gandhi
Ranch Hand

Joined: Dec 05, 2008
Posts: 221
Dear wise owen

my 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 :

And suggest, what I am doing wrong...

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 :
I agree. Here's the link:
subject: file
It's not a secret anymore!