meow00
asked on
java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException ... AbstractType in xmlbeans
Hello experts,
I am running an example from apache site, but wouldn't work ... could anyone please give me some help ? thanks.
The original example is at:
http://xmlbeans.apache.org/samples/AbstractTypes.html
This example is regarding the AbstractType of xml beans ... does anyone ever deal with this ? Please HELP !!!
-------------------------- ---------- ----------
Exception in thread "main" java.lang.NoClassDefFoundE rror: javax/xml/stream/XMLStream Exception
at java.lang.Class.getDeclare dMethods0( Native Method)
at java.lang.Class.privateGet DeclaredMe thods(Unkn own Source)
at java.lang.Class.getMethod0 (Unknown Source)
at java.lang.Class.getMethod( Unknown Source)
at org.apache.xmlbeans.XmlBea ns.buildMe thod(XmlBe ans.java:1 74)
at org.apache.xmlbeans.XmlBea ns.buildNo deMethod(X mlBeans.ja va:195)
at org.apache.xmlbeans.XmlBea ns.buildNo deToCursor Method(Xml Beans.java :232)
at org.apache.xmlbeans.XmlBea ns.<clinit >(XmlBeans .java:131)
at abstractFigures.RootDocume nt$Factory .newInstan ce(Unknown Source)
at org.apache.xmlbeans.sample s.abstract types.Abst ractTypes. buildDocum ent(Abstra ctTypes.ja va:37)
at org.apache.xmlbeans.sample s.abstract types.Abst ractTypes. main(Abstr actTypes.j ava:29)
-------------------------- ---------- ---------- -----
and the main java looks like:
/* Copyright 2004 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.
*/
package org.apache.xmlbeans.sample s.abstract types;
import abstractFigures.*;
import figures.*;
import org.apache.xmlbeans.XmlObj ect;
import org.apache.xmlbeans.XmlOpt ions;
/**
* Test class that builds a document using type substitution
*/
public class AbstractTypes
{
public static void main(String[] args)
{
buildDocument(true);
}
public static XmlObject buildDocument(boolean enableOutput)
{
XmlOptions opt = (new XmlOptions()).setSavePrett yPrint();
// Build a new document
RootDocument doc = RootDocument.Factory.newIn stance();
RootDocument.Root figures = doc.addNewRoot();
if (enableOutput)
System.out.println("Empty document:\n" + doc.xmlText(opt) + "\n");
// Add abstract figures
Shape s1 = figures.addNewFigure();
s1.setId("001");
Shape s2 = figures.addNewFigure();
s2.setId("002");
// Document contains two shapes now
// Because the shape is abstract, the document will not yet be valid
if (enableOutput)
{
System.out.println("Docume nt containing the abstract types:\n" + doc.xmlText(opt));
System.out.println("Valid = " + doc.validate() + "\n");
}
// Change the abstract figures to concrete ones
Circle circle = (Circle) s1.changeType(Circle.type) ;
circle.setRadius(10.0);
Square square = (Square) s2.changeType(Square.type) ;
square.setSide(20.0);
// Document contains two concrete shapes and is valid
if (enableOutput)
{
System.out.println("Final document:\n" + doc.xmlText(opt));
System.out.println("Vald = " + doc.validate());
}
I am running an example from apache site, but wouldn't work ... could anyone please give me some help ? thanks.
The original example is at:
http://xmlbeans.apache.org/samples/AbstractTypes.html
This example is regarding the AbstractType of xml beans ... does anyone ever deal with this ? Please HELP !!!
--------------------------
Exception in thread "main" java.lang.NoClassDefFoundE
at java.lang.Class.getDeclare
at java.lang.Class.privateGet
at java.lang.Class.getMethod0
at java.lang.Class.getMethod(
at org.apache.xmlbeans.XmlBea
at org.apache.xmlbeans.XmlBea
at org.apache.xmlbeans.XmlBea
at org.apache.xmlbeans.XmlBea
at abstractFigures.RootDocume
at org.apache.xmlbeans.sample
at org.apache.xmlbeans.sample
--------------------------
and the main java looks like:
/* Copyright 2004 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.
*/
package org.apache.xmlbeans.sample
import abstractFigures.*;
import figures.*;
import org.apache.xmlbeans.XmlObj
import org.apache.xmlbeans.XmlOpt
/**
* Test class that builds a document using type substitution
*/
public class AbstractTypes
{
public static void main(String[] args)
{
buildDocument(true);
}
public static XmlObject buildDocument(boolean enableOutput)
{
XmlOptions opt = (new XmlOptions()).setSavePrett
// Build a new document
RootDocument doc = RootDocument.Factory.newIn
RootDocument.Root figures = doc.addNewRoot();
if (enableOutput)
System.out.println("Empty document:\n" + doc.xmlText(opt) + "\n");
// Add abstract figures
Shape s1 = figures.addNewFigure();
s1.setId("001");
Shape s2 = figures.addNewFigure();
s2.setId("002");
// Document contains two shapes now
// Because the shape is abstract, the document will not yet be valid
if (enableOutput)
{
System.out.println("Docume
System.out.println("Valid = " + doc.validate() + "\n");
}
// Change the abstract figures to concrete ones
Circle circle = (Circle) s1.changeType(Circle.type)
circle.setRadius(10.0);
Square square = (Square) s2.changeType(Square.type)
square.setSide(20.0);
// Document contains two concrete shapes and is valid
if (enableOutput)
{
System.out.println("Final document:\n" + doc.xmlText(opt));
System.out.println("Vald = " + doc.validate());
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please remove it from classpath and tell me the result
ASKER
import org.apache.xmlbeans.XmlObj ect;
import org.apache.xmlbeans.XmlOpt ions;
I am in eclipse ... if I remove xbean-2.1.0.jar
It complains the above things (and some other more) can not be resolved!
import org.apache.xmlbeans.XmlOpt
I am in eclipse ... if I remove xbean-2.1.0.jar
It complains the above things (and some other more) can not be resolved!
this error is due to a name confliction
two (or more) classes have the same name, in your classpath
you should remove some paths to resolve it
If you are interested , you can test this little demo
// A.java
class A {
public static void main(String[] args) throws Exception {
Integer a;
}
}
class Integer {
int a;
}
// complie it
javac A.java
// make a jar file containing Integer.class
jar -cf a.jar Integer.class
// run demo
java -cp a.jar A
// you will encounter
Exception in thread "main" java.lang.NoClassDefFoundE rror: A
two (or more) classes have the same name, in your classpath
you should remove some paths to resolve it
If you are interested , you can test this little demo
// A.java
class A {
public static void main(String[] args) throws Exception {
Integer a;
}
}
class Integer {
int a;
}
// complie it
javac A.java
// make a jar file containing Integer.class
jar -cf a.jar Integer.class
// run demo
java -cp a.jar A
// you will encounter
Exception in thread "main" java.lang.NoClassDefFoundE
really sorry, my demo was a pitfall, :-)
ignore my last two comments
ASKER
mmm ... so maybe I created the jar file in a wrong way ?!?
I did it as follows:
[meow@cat abstracttypes]$ls
abstractBase.xsd AbstractTypes.java myfigures.jar xbean.jar
AbstractTypes.jar AbstractTypesTest.java myfigures.xsd
[meow@cat abstracttypes]$ scomp -out AbstractTypes.jar abstractBase.xsd
Time to build schema type system: 1.074 seconds
Time to generate code: 0.073 seconds
Time to compile code: 1.15 seconds
Compiled types to: AbstractTypes.jar
[meow@cat abstracttypes]$ scomp -out myfigures.jar myfigures.xsd abstractBase.xsd
Time to build schema type system: 0.854 seconds
Time to generate code: 0.085 seconds
Time to compile code: 1.203 seconds
Compiled types to: myfigures.jar
maybe I did " scomp -out myfigures.jar myfigures.xsd abstractBase.xsd" wrong ?!?
the instruction was:
-----------------------
Step1. Create the schema file "abstractBase.xsd" and compile it
to abstractbase.jar.
Step2. Create a Schema that implements the abstract types defined in
"abstractBase.xsd", and compile it with "abstractbase.jar" on the classpath.
Step3. Use the jars created in steps 1 and 2 to create an instance document
using the concrete types.
-------------------------- ---------
Maybe I did something wrong here while creating the jar ??? please help! thanks.
I did it as follows:
[meow@cat abstracttypes]$ls
abstractBase.xsd AbstractTypes.java myfigures.jar xbean.jar
AbstractTypes.jar AbstractTypesTest.java myfigures.xsd
[meow@cat abstracttypes]$ scomp -out AbstractTypes.jar abstractBase.xsd
Time to build schema type system: 1.074 seconds
Time to generate code: 0.073 seconds
Time to compile code: 1.15 seconds
Compiled types to: AbstractTypes.jar
[meow@cat abstracttypes]$ scomp -out myfigures.jar myfigures.xsd abstractBase.xsd
Time to build schema type system: 0.854 seconds
Time to generate code: 0.085 seconds
Time to compile code: 1.203 seconds
Compiled types to: myfigures.jar
maybe I did " scomp -out myfigures.jar myfigures.xsd abstractBase.xsd" wrong ?!?
the instruction was:
-----------------------
Step1. Create the schema file "abstractBase.xsd" and compile it
to abstractbase.jar.
Step2. Create a Schema that implements the abstract types defined in
"abstractBase.xsd", and compile it with "abstractbase.jar" on the classpath.
Step3. Use the jars created in steps 1 and 2 to create an instance document
using the concrete types.
--------------------------
Maybe I did something wrong here while creating the jar ??? please help! thanks.
ASKER
thanks for the help. problem solved. I need to add xmlpublic.jar and jsr173_1.0_api.jar
ASKER