1.创建jar对象
java.util.jar.JarFile jarFile;
java.io.File jar;
2.获取对象
try {
jarFile = new JarFile( jar );
}
catch ( IOException ioe ) {
log.error( "Could not configure datastore from jar: " + jar.getName(), ioe );
throw new MappingException( "Could not configure datastore from jar: " + jar.getName(), ioe );
}
3.获取jar对象内的压缩文件对象
Enumeration jarEntries = jarFile.entries();
4.使用对象
while ( jarEntries.hasMoreElements() ) {
ZipEntry ze = ( ZipEntry ) jarEntries.nextElement();
if ( ze.getName().endsWith( ".hbm.xml" ) ) {
log.info( "Found mapping documents in jar: " + ze.getName() );
try {
addInputStream( jarFile.getInputStream( ze ) ); // 重点-使用对象
}
catch ( MappingException me ) {
throw me;
}
catch ( Exception e ) {
log.error( "Could not configure datastore from jar: " + jar.getName(), e );
throw new MappingException( "Could not configure datastore from jar: " + jar.getName(), e );
}
}
}
本文介绍如何通过Java代码解析jar文件并读取其中的.hbm.xml映射文档,包括创建jar对象、获取jar对象内的压缩文件对象及使用对象。
&spm=1001.2101.3001.5002&articleId=81375002&d=1&t=3&u=8567c94d9b654657a29e5db0c8c7a7ac)
4785

被折叠的 条评论
为什么被折叠?



