473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JAXB - problem

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
4 5315

"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
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
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
> > 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
1
by: Sony Antony | last post by:
We have a situation wherin we should translate the incoming XML based on one schema to the outgoing XML that is based on another schema. Since both input and output are both XML, XSLT was the...
13
by: Christoph Brunner | last post by:
Hi, on the sun homepage i had submit to the bugparade a request for feature enhancement for the JAXB API. After a period of time sun called me to post my request to a newsgroup an get comments...
0
by: Brett Selleck | last post by:
We have an issue where the JAXB generated classes are creating an interface which references itself. The Schema is valid, and I have not seen this ran into before. The code is below. What is...
0
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
1
by: Sipayi | last post by:
'lo! Trying to use JAXB for my project. I did the following steps: a. Created xml/xsd/xjb, placed it under "com.foo.blah" b. xjc'd the xmls into "com.foo.blah.jaxb" c. Tried to unmarshal: --...
0
by: ciaran.mchale | last post by:
I used Google to find information about JAXB 2.0 and I ended up downloading a document called "The Java Architecture for XML Binding (JAXB) 2.0: Proposed Final Draft September 30, 2005". ...
0
by: mnsh | last post by:
Hello, I am new to JAXB. So I would like somebody to help me solve this problem. I have a class say Test which contains only a List which has some 6 to 7 user defined objects. I am able to...
0
by: malsh1358 | last post by:
Hi I need check required elements and attributes in JAXB java classes , if there are any value for them place it , otherwise place default value in xml file , because of it I upgrade JAXB2.0 to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.