Jaxb 如何在不使用命令提示符的情况下使用xjc
我知道给定的代码是错误的,但我想使用任何其他代码来生成pojo类。试试:Jaxb 如何在不使用命令提示符的情况下使用xjc,jaxb,xjc,Jaxb,Xjc,我知道给定的代码是错误的,但我想使用任何其他代码来生成pojo类。试试: Hi friends, I want to generate Jaxb pojo classes using xjc by java code not by using command prompt how i will use it. public static void main(String [] args) throws FileNotFoundException { t
Hi friends,
I want to generate Jaxb pojo classes using xjc by java code not by using command prompt how i will use it.
public static void main(String [] args) throws FileNotFoundException
{
try
{
JAXBContext jc = JAXBContext.newInstance(new Class[] {com.bcbsks.testjb.Report.class});
Unmarshaller um = jc.createUnmarshaller();
Report myJAXBObject = (Report)um.unmarshal(new java.io.FileInputStream("report.xsd"));
}
catch( UnmarshalException ue )
{
ue.printStackTrace();
}
catch( JAXBException je )
{
je.printStackTrace();
}
}
String[]
是传递给XJC命令的参数,XJCListener
的实现如下所示:
公共类侦听器扩展了XJCListener{
私有ConsoleErrorReporter cer=新的ConsoleErrorReporter(System.err);
私有字符串generatedPackagePath=null;
public void generatedFile(字符串文件名、整数计数、整数总数){
消息(文件名);
if(this.generatedPackagePath==null){
this.generatedPackagePath=fileName.substring(0,fileName.lastIndexOf(File.separator));
}
}
公共字符串getGeneratedPackagePath(){
返回生成的PackagePath;
}
公共无效消息(字符串消息){
System.out.println(msg);
}
公共无效错误(SAXParseException异常){
cer错误(例外);
}
公共无效fatalError(SAXParseException异常){
cer.fatalError(例外情况);
}
公共无效警告(SAXParseException异常){
cer.警告(例外);
}
公共无效信息(SAXParseException异常){
cer.信息(例外);
}
}
com.sun.tools.xjc.Driver.run(String[], XJCListener)