最近在用XML做数据对接,用到了XSD文件来对XML进行校验。XSD就是一个规范,对应于这个规范还需要有java代码来对XML处理。可以用sun.tools.internal.xjc.Driver这个类来生成java代码。可以用批处理文件来实现。但是用jdk1.6.0_04会报错,然后换了个版本的jdk就可以了。至今也不知道为什么。(两者的sun.tools.internal.xjc下面都有Drever这个类,有可能是classpath环境变量没有配置好的缘故)
报错信息
D:\implement>java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0_04\l
ib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity basics.xsd
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/internal/
bind/api/ErrorListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
D:\implement>pause
请按任意键继续. . .
批处理文件:
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity basics.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity appraise.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity confirm.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity delay.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity delivery.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity deliveryRep.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity notice.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity reply.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity report.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity review.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity delay.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity handle.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity leader.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity visitor.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity notice.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity file.xsd
java -Dfile.encoding=UTF-8 -cp "D:\Program Files\Java\jdk1.6.0\lib\tools.jar" com.sun.tools.internal.xjc.Driver -p com.ces.entity queryStatus.xsd
XML校验之sun.tools.internal.xjc.Driver
原文:http://www.cnblogs.com/lyf22/p/4274160.html