IMPORT NOT WORKING: package javax.xml.stream does not exist

Trying the following code..

=================================

package org.chinthaka.articles.stax;

import javax.xml.stream.XMLOutputFactory;

import javax.xml.stream.XMLStreamWriter;

import javax.xml.stream.XMLStreamException;

import java.io.OutputStream;

/*

* Copyright 2004,2005 The Apache Software Foundation.

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

*http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

public class SampleXMLWriter {

public void writeSampleXML(OutputStream outStream) {

try {

XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream);

// write the start element of "Article", with the namespace declaration

writer.writeStartElement("article", "Article", "http://www.article.org");

// write the article namespace

writer.writeNamespace("article", "http://www.article.org");

// write the author namespace

writer.writeNamespace("author", "http://author.org");

// write the comment

writer.writeComment("This sample1.xml is used for samples in \"Introducing StAX\" article");

// write the start element of Name element

writer.writeStartElement("Name");

// write characters

writer.writeCharacters("Introducing StAX");

// end element of Name element

writer.writeEndElement();

// write the start element of author element

writer.writeStartElement("author", "Author", "http://author.org");

// write characters

writer.writeCharacters("Eran Chinthaka");

// end element of Author element

writer.writeEndElement();

// write the processing instruction

writer.writeProcessingInstruction("This_is_a_processing_instruction");

// write the end element of Article element

writer.writeEndElement();

writer.flush();

writer.close();

} catch (XMLStreamException e) {

e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

}

}

public static void main(String[] args) {

SampleXMLWriter sampleWriter = new SampleXMLWriter();

sampleWriter.writeSampleXML(System.out);

}

}

=================================

It抯 throwing build-time error.

>> C:\java\jdk1.5.0_06\bin\javac -source 1.5 SampleXMLWriter.java

SampleXMLWriter.java:3: package javax.xml.stream does not exist

import javax.xml.stream.XMLOutputFactory;

^

SampleXMLWriter.java:4: package javax.xml.stream does not exist

import javax.xml.stream.XMLStreamWriter;

^

SampleXMLWriter.java:5: package javax.xml.stream does not exist

import javax.xml.stream.XMLStreamException;

^

SampleXMLWriter.java:26: cannot find symbol

symbol : class XMLStreamWriter

location: class org.chinthaka.articles.stax.SampleXMLWriter

XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStr

eamWriter(outStream);

^

SampleXMLWriter.java:26: cannot find symbol

symbol : variable XMLOutputFactory

location: class org.chinthaka.articles.stax.SampleXMLWriter

XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStr

eamWriter(outStream);

^

SampleXMLWriter.java:68: cannot find symbol

symbol : class XMLStreamException

location: class org.chinthaka.articles.stax.SampleXMLWriter

} catch (XMLStreamException e) {

[4025 byte] By [BiswasSa] at [2007-10-3 2:48:08]
# 1
Do you have the .jar that contains that file on your class path?that class isn't provided with Java5
Norweeda at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 2
It's a standalone application class (main). I think Ididn't get your question.
BiswasSa at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 3
> It's a standalone application class (main). I think> Ididn't get your question.It appears that your app depends upon the Java Webservices Developer Pack. This likely came with a jar file, which you need to have on your classpath.Good LuckLee
tsitha at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 4
Included sjsxp.jar; jaxb-ri-20060426\lib\jsr173_1.0_api.jar; jaxb-xjc.jar; jaxb-impl.jar; jaxb-api.jar; jaxb1-impl.jarStill No Luck..tried with 1.4 as well as 1.5 jdk. Getting same error (as mentioned in the original posting).
BiswasSa at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 5

> Included

> sjsxp.jar;

> jaxb-ri-20060426\lib\jsr173_1.0_api.jar;

> jaxb-xjc.jar;

> jaxb-impl.jar;

> jaxb-api.jar;

> jaxb1-impl.jar

>

> Still No Luck..tried with 1.4 as well as 1.5 jdk.

> Getting same error (as mentioned in the original

> posting).

We already told you what you need dude. Are you reading or what?

http://java.sun.com/webservices/archive.html

Norweeda at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 6

Dude! Thanks for your attention here. I think we are having some communication gap here.

I have the jwsdp-1.5 installed. Also have all the libs directory in the classpath.

I think I need some specific jar file and that's what I'm asking "WHICH" one?

<Sometimes we are very eager just to reply to a posting w/o going through it thoroughly>

BiswasSa at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 7

> Dude! Thanks for your attention here. I think we are

> having some communication gap here.

>

> I have the jwsdp-1.5 installed. Also have all the

> libs directory in the classpath.

>

> I think I need some specific jar file and that's

> what I'm asking "WHICH" one?

>

> <Sometimes we are very eager just to reply to a

> posting w/o going through it thoroughly>

jsr173_api.jar

Norweeda at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 8
Tried with jsr173_api.jarandjsr173_1.0_api.jarStill no luck - same error.Can anyone just try to compile this file?Thanks.
BiswasSa at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 9

I copied your code verbatim and got a clean compile using java version 1.5.0_06. I don't have the web services development kit installed, but I do have weblogic's webservices implementation jar in my classpath.

When I run it I get the following output:

$ java -classpath . SampleXMLWriter

<article:Article xmlns:article="http://www.article.org" xmlns:author="http://aut

hor.org"><!--This sample1.xml is used for samples in "Introducing StAX" article-

-><Name>Introducing StAX</Name><author:Author>Eran Chinthaka</author:Author><?Th

is_is_a_processing_instruction?></article:Article>

Good Luck

Lee

tsitha at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 10
Thanks Lee. That gave me the clue. What I needed was stax-api-1.0.1.jar and wstx-asl-3.0.0.jar specirfically in my classpath. It works.I'm sure your bea webservices.jar covers those <which I don't have>.
BiswasSa at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 11
Hi ,i have same problem and i added all jar files in classpath .but now working then i changed jdk1.4 to jdk1.5 now working finepandit
jpandita at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...
# 12
Thanks. After almost a year with the answer already given, that'll help him.
CeciNEstPasUnProgrammeura at 2007-7-14 20:36:55 > top of Java-index,Java Essentials,Java Programming...