JAXB - problem

J

jesper

Hi

I am currently following the tutorial from IBM
(http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html)

I have three problems at the moment.

1. It says else where that when the source code files are generated using
the XJC, it is possible to compile the generated source code using javac
generated\*.java generated\impl\*.java , but this only gives me 97 errors.?

2. I have typed in the source code from the tutorial :

In the tutorial it says that I have to compile the source code in the
generated directory as well, (How do I do that ? because when I compile the
generated source code it gives me errors?)

When I compile the source code below, it gives me these errors
________________________________________________________________________
----jGRASP exec: javac E:\java\xml\ex1\ProcessItem.java
ÏϧÏ
ϼ§ÏProcessItem.java:19: exception javax.xml.bind.JAXBException is never
thrown in body of corresponding try statement
ÏÏ§Ï } catch ( JAXBException e ) {
ÏÏ§Ï ^
ProcessItem.java:27: unreported exception javax.xml.bind.JAXBException; must
be caught or declared to be thrown
ÏÏ§Ï jaxbContext = JAXBContext.newInstance(packageName);
ÏÏ§Ï ^
ÏϧÏ2 errors

____________________________________________________________

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

public class ProcessItem {
private String packageName = "generated";
private String xmlFileName = "item.xml";
private JAXBContext jaxbContext;

ProcessItem() {
createItem();
readItem();
}
private void createItem() {
try {
createContext();
createUnmarshaller();
createFile();
unmarshalFile();
} catch ( JAXBException e ) {
System.out.println("There has been a problem either creating the "
+ "context for package '" + packageName +
"', creating an unmarshaller for it, or unmarshalling the '" +
xmlFileName + "' file. Formally, the problem is a " + e);
}
}
private void createContext() {
jaxbContext = JAXBContext.newInstance(packageName);
}
private void createUnmarshaller() {}
private void createFile() {}
private void unmarshalFile() {}
private void readItem() {}

public static void main(String[] args) {
new ProcessItem();
}
}

Thanks for your help,
Jesper Berthing, Denmark
 
S

Sudsy

jesper said:

Right back at ya!
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

public class ProcessItem {
private String packageName = "generated";
private String xmlFileName = "item.xml";
private JAXBContext jaxbContext;

ProcessItem() {
createItem();
readItem();
}
private void createItem() {
try {
createContext();
createUnmarshaller();
createFile();
unmarshalFile();
} catch ( JAXBException e ) {
System.out.println("There has been a problem either creating the "
+ "context for package '" + packageName +
"', creating an unmarshaller for it, or unmarshalling the '" +
xmlFileName + "' file. Formally, the problem is a " + e);
}
}
private void createContext() {
jaxbContext = JAXBContext.newInstance(packageName);
}

You missed something here. Try this:

private void createContext() throws JAXBException {
jaxbContext = ...

You probably missed it when transcribing the source since it
might have been split across lines, i.e.:

private void createContext()
throws JAXBException {
jaxbContext = ...

Both errors arise from the same problem. The first is complaining
that you're catching an exception which is never thrown (since you
don't specify that createContext throws the exception) while the
second is complaining that you don't handle the exception thrown
by JAXBContext.newInstance( ... ).
Does this make sense to you?
 
J

jesper

Thansk that helped.

But is there anybody that have been able to compile the generated source
code based on the XSD files using JAXB?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top