xmlbeans 使用 以及 java.io.IOException CreateProcess error=2错误处理

1. 下载配置XmlBeans

a) 下载XmlBeans,假定下载到C:\xmlbeans-2.3.0

b) 设置环境变量XMLBEANS_HOME= C:\xmlbeans-2.3.0

c)创建 runreport.xsd 、runreport.xsdconfig 文件
如: runreport.xsd 格式:
<?xml version="1.0" encoding="UTF-8"?>
         <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  elementFormDefault="qualified">
         <xs:element name="RunReport">
           <xs:complexType >
             <xs:sequence>
               <xs:element name="reportTitle" type="xs:string"/>
               <xs:element name="publishtime" type="xs:string"/>
               <xs:element name="publisher" type="xs:string"/>
               <xs:element name="runGroup" type="runGroup"/>
               <xs:element name="showColor" type="showColor"/>
             </xs:sequence>
           </xs:complexType>
         </xs:element>
        
         <xs:complexType name="runGroup">
             <xs:sequence>
               <xs:element name="name" type="xs:string"/>
               <xs:element maxOccurs="unbounded" minOccurs="0" name="runGroups"
                           type="runGropItem"/>
             </xs:sequence>
         </xs:complexType>

<xs:complexType name="showColor">
             <xs:sequence>
               <xs:element name="colorValue" type="xs:string"/>
               <xs:element name="gradeValue" type="xs:string"/>
             </xs:sequence>
         </xs:complexType>


         <xs:complexType name="runGropItem">
             <xs:sequence>
               <xs:element name="id" type="xs:string"/>
               <xs:element name="groupid" type="xs:string"/>
               <xs:element name="unitid" type="xs:string"/>
               <xs:element name="indicatorid" type="xs:string"/>
               <xs:element name="unitName" type="xs:string"/>
               <xs:element name="unitIp" type="xs:string"/>
       <xs:element name="indicatorName" type="xs:string"/>
               <xs:element name="incidentstatus" type="xs:string"/>
       <xs:element name="description" type="xs:string"/>
               <xs:element name="remark" type="xs:string"/>
             </xs:sequence>
         </xs:complexType>
        
      </xs:schema>

runreport.xsdconfig 文件是规定报名 如:

<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
      <xb:namespace>
         <xb:package>com.wm.biz.report.xmlbean.runreport</xb:package>
      </xb:namespace>
</xb:config>

2. 使用XmlBeans生成runreport.jar
在此之前要把 jdk 环境变量配置好。
a) 在新建环境变量中加入 XMLBEANS_HOME = C:\xmlbeans-2.3.0
b) 在环境变量PATH中加入%XMLBEANS_HOME%\bin
c) 在环境变量classpath中加入%XMLBEANS_HOME%\lib

d) c:\xmlbeans-2.3.0\samples\Any\schemas>scomp -out runreport.jar runreport.xsd -co
mpiler %JAVA_HOME%\bin\javac runreport.xsdconfig

e). 如果出现以下错误:

c:\xmlbeans-2.3.0\samples\Any\schemas>scomp -out runreport.jar runreport.xsd -co
mpiler %JAVA_HOME%\bin\javac runreport.xsdconfig
Time to build schema type system: 0.732 seconds
Time to generate code: 0.141 seconds
java.io.IOException: CreateProcess: C:\Program @C:\Users\wangmeng\AppData\Local\
Temp\javac8366 error=2
null
java.io.IOException: CreateProcess: C:\Program @C:\Users\wangmeng\AppData\Local\
Temp\javac8366 error=2
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at org.apache.xmlbeans.impl.tool.CodeGenUtil.externalCompile(CodeGenUtil
.java:231)
        at org.apache.xmlbeans.impl.tool.SchemaCompiler.compile(SchemaCompiler.j
ava:1154)
        at org.apache.xmlbeans.impl.tool.SchemaCompiler.main(SchemaCompiler.java
:373)
BUILD FAILED

该错误是有在安装 jdk 的时候,安装路径为 C:\Program Files\Java;其 解决办发在安装jdk不要装 Program Files 文件夹中,
因为该文件夹有空格 ,在 cmd 程序中识别不了。

f)正确运行结果:
c:\xmlbeans-2.3.0\samples\Any\schemas>scomp -out runreport.jar runreport.xsd -co
mpiler %JAVA_HOME%\bin\javac runreport.xsdconfig
Time to build schema type system: 0.694 seconds
Time to generate code: 0.16 seconds
Time to compile code: 1.761 seconds
Compiled types to: runreport.jar

注意在C:\xmlbeans-2.3.0\samples\Any\schemas 中可以找到 runreport.jar



你可能感兴趣的:(java,jdk,C++,c,C#)