How to reduce TrueVFS dependencies

╄→尐↘猪︶ㄣ 提交于 2020-01-03 21:02:29

问题


I was recently looking for a decent library to work with ZIP files. Several post on SO recommended TrueVFS, formerly TrueZip.

I need to extract individual files, modify them, and put them back to archive, overriding the old one. The goal is to write library to upload Java macros to ODF files, Libre Office/Open Office documents, which are in fact standard ZIP files.

The TrueVFS documentation lacks basics, so it took me some time and experimentation to find that one can do it very easily:

import net.java.truevfs.access.TArchiveDetector;
import net.java.truevfs.access.TFile;
import net.java.truevfs.access.TVFS;
import net.java.truevfs.comp.zipdriver.ZipDriver;

public class BasicOperations {

    public File extractFileFromArchive(File archiveFile, String pathInArchive, File destFolder) throws Exception {
        TFile archivedFile = new TFile(archiveFile, pathInArchive);
        File destFile = new File(destFolder, pathInArchive);
        destFile.getParentFile().mkdirs();
        archivedFile.cp_rp(destFile);
        return destFile;
    }

    public void addFileToArchive(File archiveFile, String pathInArchive, File srcFile) throws Exception {
        TFile destArchiveFile = new TFile(archiveFile, pathInArchive, new TArchiveDetector("zip", new ZipDriver()));
        TFile.cp_p(srcFile, destArchiveFile);
    }
}

So far good. But there is a problem - massive dependencies!. Even with basic profile:

    <dependency>
        <groupId>net.java.truevfs</groupId>
        <artifactId>truevfs-profile-default</artifactId>
        <version>0.11.0</version>
        <type>pom</type>
    </dependency>

Maven resolves close to 50 (!!!) dependent libraries.

It is not all bad, some of them are marked as provided (not sure what implication it has for a desktop application) and most most of libraries are quite small, micro libraries in fact. Most of them from the same author. Looks like he duplicated (extracted) lots of code from Apache Jakarta libraries. Some libraries I managed to exclude, like Swing GUI to enter password for encrypted archives, but most dependencies are quite stubborn.

Most outrageous is dependency on scala-library (org.scala-lang:scala-library:2.11.6). TrueVFS is supposed to be Java library. I have checked source code but nothing relevant seems to be using it. Is it some obscure driver? When I try to exclude it from dependencies maven, my test fails with java.lang.ClassNotFoundException: scala.Immutable.

So question is, please, could someone share a Maven configuration, or advice code change, which would significantly reduce dependencies, namely scala-library? I just need a simple R/W access to simple ZIP files.

来源:https://stackoverflow.com/questions/33160554/how-to-reduce-truevfs-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!