By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.

JAXB - problem

P: n/a
Hi

I am currently following the tutorial from IBM
(http://www-106.ibm.com/developerwork...w-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

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"jesper" <no****@nospam.dk> wrote in message
news:3f***********************@dread16.news.tele.d k...
Hi

I am currently following the tutorial from IBM
(http://www-106.ibm.com/developerwork...w-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

try this. just add "throws javax.xml.bind.JAXBException" after the method
name
.....
private void createContext() throws javax.xml.bind.JAXBException {
jaxbContext = JAXBContext.newInstance(packageName);
}
....

i think this is the only problem concerning these 2 errors you mentioned.

__________________________________________________ __________

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

Jul 17 '05 #2

P: n/a
Thanks Igor, that solved the problem.

But I think that I have a problem still, can it be the PATH variables that I
have to setup. below is what I have set up for the JAVA JDK and JAXB.
Do I need set any thing else up?

CLASSPATH=C:\jwsdp-1.3\jaxb\lib\jaxb-api.jar;C:\jwsdp-1.3\jaxb\lib\jaxb-impl
..jar;C:\jwsdp-1.3\jaxb\lib\jaxb-libs.jar

PATH=C:\jwsdp-1.3\jwsdp-shared\bin;C:\jwsdp-1.3\jaxb\bin;c:\j2sdk1.4.2_01\bi
n

JAVA_HOME=c:\j2sdk1.4.2_01

"Igor L" <pa*********@yahoo.com.hk> skrev i en meddelelse
news:bt**********@sunce.iskon.hr...

"jesper" <no****@nospam.dk> wrote in message
news:3f***********************@dread16.news.tele.d k...
Hi

I am currently following the tutorial from IBM
(http://www-106.ibm.com/developerwork...w-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


try this. just add "throws javax.xml.bind.JAXBException" after the method
name
....
private void createContext() throws javax.xml.bind.JAXBException {
jaxbContext = JAXBContext.newInstance(packageName);
}
...

i think this is the only problem concerning these 2 errors you mentioned.

__________________________________________________ __________

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


Jul 17 '05 #3

P: n/a
I don't think there is any other problem. It's an error in code. In Java, if
one method doesn't catch an exception (with try catch block), you have to
explicitly say "throws ...someException..." (unless it's a runtime exception
like NullPointerException, ArrayIndexOutOfBoundsException, etc.)
For more information see Java tutorial, part about exceptions.
I hope this will help.

Igor
"jesper" <no****@nospam.dk> wrote in message
news:3f***********************@dread16.news.tele.d k...
Thanks Igor, that solved the problem.

But I think that I have a problem still, can it be the PATH variables that I have to setup. below is what I have set up for the JAVA JDK and JAXB.
Do I need set any thing else up?

CLASSPATH=C:\jwsdp-1.3\jaxb\lib\jaxb-api.jar;C:\jwsdp-1.3\jaxb\lib\jaxb-impl .jar;C:\jwsdp-1.3\jaxb\lib\jaxb-libs.jar

PATH=C:\jwsdp-1.3\jwsdp-shared\bin;C:\jwsdp-1.3\jaxb\bin;c:\j2sdk1.4.2_01\bi n

JAVA_HOME=c:\j2sdk1.4.2_01

"Igor L" <pa*********@yahoo.com.hk> skrev i en meddelelse
news:bt**********@sunce.iskon.hr...

"jesper" <no****@nospam.dk> wrote in message
news:3f***********************@dread16.news.tele.d k...
Hi

I am currently following the tutorial from IBM
(http://www-106.ibm.com/developerwork...w-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


try this. just add "throws javax.xml.bind.JAXBException" after the method name
....
private void createContext() throws javax.xml.bind.JAXBException {
jaxbContext = JAXBContext.newInstance(packageName);
}
...

i think this is the only problem concerning these 2 errors you mentioned.
__________________________________________________ __________

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



Jul 17 '05 #4

P: n/a
> > Thanks Igor, that solved the problem.

But I think that I have a problem still, can it be the PATH variables that

I
have to setup. below is what I have set up for the JAVA JDK and JAXB.
Do I need set any thing else up?

CLASSPATH=C:\jwsdp-1.3\jaxb\lib\jaxb-api.jar;C:\jwsdp-1.3\jaxb\lib\jaxb-impl
.jar;C:\jwsdp-1.3\jaxb\lib\jaxb-libs.jar


I also have these JAXB related libs on my classpath, hope it helps -
ran into the same problems last week when I updated my JWSDP from 1.1
to 1.3:

c:\jwsdp-1.3\jaxb\lib\jaxb-xjc.jar;C:\jwsdp-1.3\jwsdp-shared\lib\relaxngDatatype.jar;

Brad
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.