-->

Binding in JIBX

2019-06-13 18:34发布

问题:

Hi I just started using JIBX and I am having difficulty grasping the Binding concept. I have generated the JAVA classes from an XSD File I am using windows and here is how my folders are structures

d:\Libraries\ This folder contains the jibx folder downloaded so the rar libraries like jibx-tools.jar are in d:\Libraries\jibx\lib.....

Now the Libraries folder also contains a folder called dwcode2 I have an XSD File called starter.xsd in D:\Libraries\jibx\dwcode2\

I generated the JAVA files using the command in DOS D:\Libraries\jibx\dwcode2>java -cp ..\lib\jibx-tools.jar org.jibx.schema.codegen.CodeGen -t gen\src -w starter.xsd

as a result JAVA files were generated in D:\Libraries\jibx\dwcode2\gen\src\org\jibx\

and the binding.xml was generated in D:\Libraries\jibx\dwcode2\gen\src

Now I want to compile and bind the file (Could anyone also tell me why do we have to compile and bind the XML ) So i did the following D:\Libraries\jibx\dwcode2\gen\src>java -jar "D:\Java Libraries"\jibx\lib\jibx-bind.jar binding.xml

Error: Unable to find type org.jibx.starter.Shipping; on format element at (line 3, col 66, in binding.xml)Error: Cannot find information for class org.jibx.starter.Item; on mapping element at (line 4, col 79, in binding.xml)Error: Cannot find information for class org.jibx.starter.Address; on mapping element at (line 9, col 85, in binding.xml) Error: Cannot find information for class org.jibx.starter.Customer; on mapping element at (line 17, col 87, in binding.xml)Error: Cannot find information for class org.jibx.starter.Order; on mapping element at (line 22, col 81, in binding.xml) Error: Cannot find information for class org.jibx.starter.Order; on mapping element at (line 35, col 56, in binding.xml) Error running binding compiler org.jibx.runtime.JiBXException: Binding binding.xml is unusable because of validation errors at org.jibx.binding.Utility.loadBinding(Utility.java:358)   at org.jibx.binding.Utility.loadFileBinding(Utility.java:420)
                    at org.jibx.binding.Compile.compile(Compile.java:217)
                    at org.jibx.binding.Compile.main(Compile.java:384)

Could anyone please tell me what i am doing wrong ?? How can i fix this problem ? and why do we have to bind ??

回答1:

Rajesh,

When you use the JiBX code generator, you need to do three steps:
1. Use the code generator to generate java code and a binding file from XML schema
2. Compile your java code
3. Use the binding compiler to modify your java class files so they can generate XML schema.
I can't see your schema, so why don't you do a test to see if the problem is your schema or your command lines:
- Place your schema in an empty directory and run these commands.

java -cp ../lib/jibx-tools.jar org.jibx.schema.codegen.CodeGen starter.xsd
javac -cp ../lib/jibx-run.jar:. org/jibx/starter/Shipping.java
java -cp ../lib/jibx-bind.jar:. org.jibx.binding.Compile binding.xml

Of course your will replace the path to the lib directory with your path (ie., c:\Library).

If this works, now you can organize your project into folders.

You can find complete documentation on our site at www.jibx.org.

To really simplify your life, I would recommend using the maven plugin. Configuration is much easier.

I hope this helps.

Don



回答2:

You have maybe an error on the build.xml. Is you're classpath location correct ? Open buid.xml, go on the field where the first line is . Look at under the line .

if it's "bin", you must have binding.xml and the package containing the .class files in "bin". If it's in bin/classes or other path you will have this error because it will not found binding.xml so change build.xml to write bin/classes.

If you use eclipse, you have to generate the classes, compile, refresh and then execute the bind option, else this error appear.



标签: java xml xsd jibx