As is typical of me I probably don't understand your question or problem
thoroughly. Well you said you couldn't use Maven so a non-maven response is
what you're getting. :)
Typical XmlBeans usage is to generate the classes in a jar and to then
reference this jar while developing your code. If you can't use Ant or
Maven for some reason there is a command line utility to do this. I
personally have a little bat file I use for generating demos:
scomp -out lib/%1.jar xsd/%1.xsd
If however there is some reason you have to "compile on the fly" I refer you
to an excellent discussion of doing this:
http://www.oracle.com/technetwork/articles/entarch/incremental-compilation-x
mlbeans-089127.html
Please reply with your use case for this.
As to your questions:
* Why do you get "URL "./th08_extern.xsd" is not well-formed"?
Possibly because "./th08_extern.xsd" is not well-formed.
Post it and we'll see. My demo of this worked correctly (see below).
* I want everything XmlBeans generates in the package
"ch.mypackage"; how can I to this?
This is controlled by the schema namespace setting:
http://www.w3.org/2001/XMLSchema";>
Note that in typical "Computer Science Weenie my way is
better" fashion the namespace is llq.hlq. XmlBeans will generate classes in
the more typical hlq.llq package.
* Why is this class not generated?
Well, nothing in your posted source showed that you compiled
the generated java files. Refer to the URL above for more detail. Or
previously compile using scomp as above.
Cordially,
Paul Gillen
http://www.w3.org/2001/XMLSchema";>
http://www.w3.org/2001/XMLSchema";>
package org.eltesto;
import java.io.File;
import org.apache.xmlbeans.BindingConfig;
import org.apache.xmlbeans.Filer;
import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.apache.xmlbeans.impl.util.FilerImpl;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
public class Main {
public static void main(String[] args) throws Exception {
Main m = new Main();
m.go(args);
}
private void go(String[] args) throws Exception {
File xsd = new File("xsd/Root.xsd");
SchemaDocument xsdo = SchemaDocument.Factory.parse(xsd);
final Filer filer = new FilerImpl(null, new File("src/"),
null, true, true);
final XmlOptions options = new XmlOptions();
options.setCompileDownloadUrls();
BindingConfig config = new BindingConfig();
XmlBeans.compileXmlBeans("TypeName", null, new XmlObject[] {
xsdo }, config, null, filer, options);
}
}
-Original Message-
From: Michael Szalay [mailto:michael.sza...@abacus.ch]
Sent: Wednesday, August 21, 2013 9:39 AM
To: user@xmlbeans.apache.org
Subject: Question about generating Java Source Code from XML Schemas
Hi all
I have some xsd schemas in my source tree and I want to generate java
sources with XML Beans.
I cannot use ant or maven task, I have to do it in plain java.
I use the following java code:
final InputStream schema1Stream =
BeanGenerator.class.getResourceAsStream("xsd/schema1.xsd");
final XmlObject schema1 = XmlObject.Factory.parse(schema1Stream);
final InputStream schema2Stream =
BeanGenerator.class.getResourceAsStream("xsd/schema2.xsd");
final XmlObject schema2 = XmlObject.Factory.parse(schema2Stream);
final XmlObject[] schemas = { schema1, schema2 }; final BindingConfig config
= new BindingConfig() {
@Override
public String lookupPackageForNamespace(String uri) {
return "ch.mypackage";
}
};
final Filer filer = new FilerImpl(null, new File(".java/src/"), null, true,
true); final XmlOptions options = new XmlOptions();
options.setCompileDownloadUrls(); XmlBeans.compileXmlBeans(null, null,
schemas, config, null, filer, options);
I have questions:
1) The schemas have include statements like this:
How can I make XmlBeans to include this schemas? Its located in the same
folder as the original schema, but XMLBeans does not find it:
URL "./th08_extern.xsd" is not well-formed
how to solve that?
2) I want everything XmlBeans generates in the package "ch.mypackage".
How can I to this? XmlBeans generates a lot of other stuff like xsb files
which are not in that package.
How can I say to XmlBeans to not generate this files?
3) When I use one of the generated classes, there is the following runtime
error:
java.lang.RuntimeException: Cannot load SchemaTypeSystem. Unable to load
class with name
schemaorg_apache_xmlbeans.system.s2EF0617F3F8756BE3