启动的时候复制jar包里面的文件出来,给jvm调用
    
  
      
      
      
      
    
        
          
                  
    
    
    
    
                  成功方式
利用jarFile来实现 文件读取
参考链接 https://www.codenong.com/1463192/
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 
 | String destDirPath = getCurrentDirPath();// 读取jar文件
 URL resource = this.getClass().getResource("/PSTools");
 JarURLConnection conn = (JarURLConnection) resource.openConnection();
 JarFile jarFile = conn.getJarFile();
 final Enumeration<JarEntry> entries = jarFile.entries();
 while (entries.hasMoreElements()) {
 final JarEntry entry = entries.nextElement();
 if (entry.getName().contains(".exe")) {
 System.out.println("File :" + entry.getName());
 JarEntry fileEntry = jarFile.getJarEntry(entry.getName());
 InputStream input = jarFile.getInputStream(fileEntry);
 FileUtils.copyInputStreamToFile(input,new File(destDirPath,entry.getName()));
 }
 }
 
 | 
错误1
主要是 希望列出jar内的文件路径来实现读取 jar包内指定路径下的所有文件并复制出来
| 12
 3
 4
 5
 
 | File[] files = new File(currentDirPath).listFiles();String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
 for (File file : files) {
 FileUtils.copyDirectory(file,new File(path));
 }
 
 | 
错误2
这个是这参考这位博主的文章 https://yebukong.com/article/1102629952022507521.html
没有生效 读取读取不到 jar包内 classpath 的文件
| 12
 3
 4
 5
 
 | /*  ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();Resource[] resources = resolver.getResources("static/blog/**");
 for (Resource resource : resources) {
 FreeMarkerUtil.copyResourceToFile(resource, aPath,"/static/blog/");
 }*/
 
 | 
错误3
目前只能读到文件
| 1
 | String path = new File(getClass().getResource("").getPath()).getParentFile().getParent());
 | 
错误4
目前读取不到jar 下面的文件夹和具体文件
| 12
 
 | URL[] urls = {this.getClass().getResource("/PSTools") };URLClassLoader cl = URLClassLoader.newInstance(urls);
 
 |