如何通过java编码解压缩EAR> JAR文件后获取hibernate配置文件

时间:2015-11-08 05:23:21

标签: java maven ear zipfile

我需要获取一个JAR文件中的休眠配置文件,同样这个JAR文件通过java编码在一个EAR文件中。

One Ear包含许多Jar文件,一个Jar文件包含单个hibernate配置文件。

所以结构就是这样,

一个EAR -

##    --Jar1 ##
 ###     ---Folder Structure, and somewhere in the structure hibernate cfg file resides ###
   ## --Jar2 ##
    ### ---Folder structure, and hibernate cfg file ###
    ##--Jar3 and so on ##  

我试过的是我使用Java API的ZipFileInputStream读取器来解压缩EAR文件,但我没有获得Jar文件的真实路径(绝对路径),以便我可以提取Jar文件和从这些提取层次结构获取我想要的hibernate cfg文件。

我能够使用java编码使用java API的ZipFileInputStream读取器解压缩直接包含hibernate cfg文件的示例EAR。但我的要求是EAR包含JAR,这个JAR包含我正在寻找的配置文件。这就是我通过java编程所做的一切

以下是包含.cfg.xml文件的EAR的代码段。

FileInputStream fis = new FileInputStream("C:/Users/USER/Downloads/ContactManager.ear"); 
      ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); 
      ZipEntry entry = null; String pathName;
      String fileName; 
      while ((entry = zis.getNextEntry()) != null) { pathName = entry.getName(); 
      if(pathName.endsWith(".cfg.xml")){ System.out.println("path name "+pathName);

请告诉我实现这项任务的最佳方法。 谢谢,

1 个答案:

答案 0 :(得分:0)

尝试TrueZip或者只是将ZIP文件内容解压缩到临时目录,并尝试将其作为单独的ZIP文件读取。