which .jar file has javax.xml.stream.*?
Asked Answered
T

2

20

I have problems again with my Mac running Java 1.5.... where do I get a .jar file that has javax.xml.stream.XMLInputFactory ? I want to use StAX but don't know how to get it set up right.


I can't seem to get this setup. I've now downloaded jaxp-api.jar, jsr173_1.0_api.jar, sjsxp.jar, stax-api-1.0.1.jar, stax2-api-3.0.1.jar, and woodstox-core-asl-4.0.5.jar; put them all into my java/lib/ext directory, made sure they're on my eclipse build path, removed the Mac com.apple.quarantine extended attribute, did a "chmod a+x" on the .jar files, and I still get the following error trying to import javax.xml.stream.XMLInputFactory;

Access restriction: The type XMLInputFactory is not accessible due to restriction on required library /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext/jsr173_1.0_api.jar

What do I need to do?

Tedious answered 23/8, 2009 at 18:53 Comment(0)
E
27

StAX is not a part of Java 5; you'll find it in Java 6, however. For Java 5, you'll need to download a StAX implementation and place it in the classpath.

Woodstox is one such implementation. You could also use the Sun Java StAX XML processor, which has made its way into Java SE 6.

Unless I'm mistaken, both of these implementations will eventually use the jsr173_api.jar, where you'll find the javax.xml.stream package.

Update:

The Woodstox documentation would refer you to download the StAX 1.0.1 API jar (required when you use the standard StAX API); the StAX2 API jar in Woodstox will not contain the javax.xml.stream package (although you'll need both JARs at runtime). The Sun implementation depends on the stax-utils project.

Update 2

Installing JSXP

The download files area of SJSXP looks a bit weird, in that you have a class file, instead of build JARs. However, all that is needed to obtain the SJSXP JAR, is to execute the class file, which unpacks the distribution.

Getting the StAX API JAR

The StAX API jar (jsr173_api.jar or the like) can be obtained from the StAX utilities project. It needs to be in the same directory as the sjsxp jar.

Using the JARs in Eclipse

It is not necessary to add the JARs to lib/ext of the JDK. It is enough to add the two JARs to the Build Path of the project.

Egocentric answered 23/8, 2009 at 19:24 Comment(3)
OK I am trying to deal with this calmly and avoid screaming. I have downloaded SJSXP and put both sjsxp.jar and jsr173_1.0_api.jar into the java /lib/ext directory, but Eclipse refuses to realize there's a javax.xml.stream.XMLInputFactory in the classpath >:( help!Tedious
Are you sure Eclipse is using the same JRE that you are expecting it to? Putting stuff in lib/ext is a bit fragile. It should be fine on the standard classpath.Unvalued
Updated the answer to indicate what needs to be done to include SJSXP & JSR 173 API in Eclipse. Tested on the SJSXP example (cursor.CursorParse example).Egocentric
I
19

Can I point you to findjar.com, which allows you to enter a classname and determine which jar is required.

e.g. XMLInputFactory yields

jsr173_1.0_api.jar
jsr173_api.jar
stax-api-1.0.1.jar
stax-api-1.0.1.jar
stax-api-1.0.jar
groovysoap-all-jsr06-0.1.jar
Impassioned answered 23/8, 2009 at 19:23 Comment(1)
indeed, findjar is an invaluable tool, have used it in the past with JavaEE and IBM's WebSphere stuff to find where some class was that was poorly documentedAmazonas

© 2022 - 2024 — McMap. All rights reserved.