openjdk 编译_使用OpenJDK 11运行JAXB xjc编译器
openjdk 編譯
如文章“ 要從Java 11中刪除的API ”所述,JDK 11不再包括 JAXB實現(xiàn)。 在本文中,我將結(jié)合使用JAXB ( 用于XML綁定的Java體系結(jié)構(gòu) ) 參考實現(xiàn)提供的xjc編譯器和OpenJDK 11,將XML模式文件編譯成Java類。
在Java SE 6之前,想要與Java SE應(yīng)用程序一起使用JAXB的開發(fā)人員需要單獨獲取JAXB實現(xiàn),因為Java發(fā)行版未提供該實現(xiàn)。 從Java SE 6開始,Java包含一個JAXB實現(xiàn)。 這在許多情況下很方便,但是當(dāng)開發(fā)人員希望使用比JDK所提供的版本更高或不同的JAXB 實現(xiàn)時,事情會變得有些困難 。 當(dāng)OpenJDK 9引入了模塊化時, JAXB實現(xiàn)被移到了java.xml.bind模塊中 ,并標(biāo)記為不推薦 刪除 。 JAXB實現(xiàn) 與JDK 11一起全部刪除 。 這篇文章探討了將JAXB的xjc編譯器與OpenJDK 11一起使用 。
由于JDK 11不再包含JAXB的實現(xiàn),因此必須單獨購買一個。 在本文中,我將使用2.3.0版的JAXB參考實現(xiàn) 。 本文中使用的JDK版本是JDK 11.0.2 General-Availability Release 。
在不帶參數(shù)的情況下運行xjc腳本會導(dǎo)致將幫助/用法呈現(xiàn)到標(biāo)準(zhǔn)輸出中。
Usage: xjc [-options ...] <schema file/URL/dir/jar> ... [-b <bindinfo>] ... If dir is specified, all schema files in it will be compiled. If jar is specified, /META-INF/sun-jaxb.episode binding file will be compiled. Options:-nv : do not perform strict validation of the input schema(s)-extension : allow vendor extensions - do not strictly follow theCompatibility Rules and App E.2 from the JAXB Spec-b <file/dir> : specify external bindings files (each <file> must have its own -b)If a directory is given, **/*.xjb is searched-d <dir> : generated files will go into this directory-p <pkg> : specifies the target package-m <name> : generate module-info.java with given Java module name-httpproxy <proxy> : set HTTP/HTTPS proxy. Format is [user[:password]@]proxyHost:proxyPort-httpproxyfile <f> : Works like -httpproxy but takes the argument in a file to protect password -classpath <arg> : specify where to find user class files-catalog <file> : specify catalog files to resolve external entity referencessupport TR9401, XCatalog, and OASIS XML Catalog format.-readOnly : generated files will be in read-only mode-npa : suppress generation of package level annotations (**/package-info.java)-no-header : suppress generation of a file header with timestamp-target (2.0|2.1) : behave like XJC 2.0 or 2.1 and generate code that doesnt use any 2.2 features.-encoding <encoding> : specify character encoding for generated source files-enableIntrospection : enable correct generation of Boolean getters/setters to enable Bean Introspection apis -disableXmlSecurity : disables XML security features when parsing XML documents -contentForWildcard : generates content property for types with multiple xs:any derived elements -xmlschema : treat input as W3C XML Schema (default)-dtd : treat input as XML DTD (experimental,unsupported)-wsdl : treat input as WSDL and compile schemas inside it (experimental,unsupported)-verbose : be extra verbose-quiet : suppress compiler output-help : display this help message-version : display version information-fullversion : display full version informationExtensions:-Xinject-code : inject specified Java code fragments into the generated code-Xlocator : enable source location support for generated code-Xsync-methods : generate accessor methods with the 'synchronized' keyword-mark-generated : mark the generated code as @javax.annotation.Generated-episode <FILE> : generate the episode file for separate compilation-Xpropertyaccessors : Use XmlAccessType PROPERTY instead of FIELD for generated classesxjc編譯器腳本(bash文件和DOS批處理文件)很方便調(diào)用jaxb-xjc.jar 。 腳本將其作為可執(zhí)行JAR ( java -jar )調(diào)用,如以下摘錄所示:
- Windows版本( xjc.bat ):
%JAVA% %XJC_OPTS% -jar "%JAXB_HOME%\lib\jaxb-xjc.jar" %* - Linux版本( xjc.sh ):
exec "$JAVA" $XJC_OPTS -jar "$JAXB_HOME/lib/jaxb-xjc.jar" "$@"
如上面的腳本摘錄所示,Java啟動器的調(diào)用中包含一個環(huán)境變量XJC_OPTS 。 不幸的是,JAXB參考實現(xiàn)JAR不能簡單地通過-classpath添加到類路徑中,因為使用java -jar 運行可執(zhí)行的JAR僅遵守通過MANIFEST.MF的Class-Path (該條目存在于jaxb-ri-2.3.0.jar作為“ Class-Path: jaxb-core.jar jaxb-impl.jar ”)。
一種解決方法是修改腳本以將JAR用作常規(guī)JAR(不帶-jar )并顯式執(zhí)行XXCFacade類,以便可以將類路徑顯式提供給Java啟動器 。 Windows xjc.bat腳本xjc.bat進行了演示:
%JAVA% -cp C:\lib\javax.activation-api-1.2.0.jar;C:\jaxb-ri-2.3.0\lib\jaxb-xjc.jar com.sun.tools.xjc.XJCFacade %*
除了JAXB參考實現(xiàn)JAR javax.activation-api-1.2.0.jar ,我還需要在類路徑中包括javax.activation-api-1.2.0.jar JAR,因為JavaBeans Application Framework ( JAF )是JDK也不再提供的依賴項(通過刪除JAXB的同一JEP 320刪除)。
當(dāng)然,也可能根本不使用XJC腳本,而是直接運行Java啟動器。 該腳本確保設(shè)置了環(huán)境變量JAXB_HOME 。 該環(huán)境變量應(yīng)指向JAXB參考實現(xiàn)擴展到的目錄。
通過這些更改,可以使用JDK 11在命令行上針對XSD執(zhí)行JAXB xjc編譯器。
翻譯自: https://www.javacodegeeks.com/2019/01/running-jaxb-xjc-compiler-with-openjdk-11.html
openjdk 編譯
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的openjdk 编译_使用OpenJDK 11运行JAXB xjc编译器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 家用小型激光打印机(家用小型激光打印机性
- 下一篇: starter_您是否尝试过MicroP