TrueZIP 7 is built as a multi-module Apache Maven project. Using its Maven archetype, getting started with TrueZIP 7 is really easy. But how could you use TrueZIP 7 without Maven? This article not just shows you how to do it, but also why this is really only a second best choice.
Why Maven?
Before I show you how you can use TrueZIP 7 without using Maven, let’s quickly check what you’re going to miss if you did:
- The TrueZIP File* Application Archetype
creates a mini-app with typical lifecyle phases:
- Setup: Configure the TrueZIP File* API to recognize only the file suffixes of the archive types you need to access, e.g. ZIP or TAR.GZ.
- Work: Run the application’s custom tasks.
- Sync: Commit any unsynchronized changes to archive files and enables you to catch exceptions along the way.</ol>
- The Maven Project Object Model makes it easy to select just the modules you need, which yields the following benefits:
- It makes the above setup phase redundant in most cases.
- It shrinks down the code size of your application.
‘Nuff advertising for Maven! Still not convinced? Then let’s see how we can avoid using Maven.
No, Thanks!
After all, TrueZIP 7 ships as a bunch of JARs.
Fortunately, there is an all-in-one JAR available for download at Maven Central.
To locate the latest release, browse to http://search.maven.org and do an advanced search for
the group ID de.schlichtherle.truezip
, the artifact ID truezip-samples
and the classifier jar-with-dependencies
(or simply
click here).
For the release of TrueZIP 7.0, you could also directly download it from
http://repo1.maven.org/maven2/de/schlichtherle/truezip/truezip-samples/7.0/truezip-samples-7.0-jar-with-dependencies.jar.
This all-in-one JAR saves you from grabbing the module JARs individually. However, as the name implies, it includes all sample code which bloats the code size of your application. More importantly, this will also initially set up the TrueZIP File* API to recognize all canonical file suffixes of all supported archive file types in TrueZIP 7.0 - see the table at the end of this post. This may yield some unwanted side effects on any unintended access to an archive file:
- The virtual file system of an archive file is automatically mounted.
- This may confuse the application because the archive file unexpectedly behaves like a directory instead of like a file.
- In case of TAR files, this can be considerably slow because they do not provide a central directory so that the driver needs to unpack the entire archive file into a temporary directory.
- In case of an EXE file, an attempt is made to locate the central directory of a self extracting ZIP file which causes the entire file to be read.
- A Swing or console based dialog prompts the user for a password to access a RAES encrypted ZIP file.
In order to avoid these unwanted side effects, you should always configure the TrueZIP File* API to recognize only the
file suffixes of the archive types you need to access.
There’s a sample available for this task at
https://christian-schlichtherle.bitbucket.io/truezip/usecases/aff.html.
You should also check the Javadoc for the class
de.schlichtherle.truezip.file.TArchiveDetector
.
Initial Setup
Following are the canonical archive file suffixes which are initially recognized when using the TrueZIP File* API in
truezip-samples-7.0-jar-with-dependencies.jar
:
Canonical File Suffixes | Archive File Format |
---|---|
`ear`, `jar`, `war` | Java Archive |
`exe` | Self Extracting ZIP File |
`odb`, `odf`, `odg`, `odm`, `odp`, `ods`, `odt`, `otg`, `oth`, `otp`, `ots`, `ott` | OpenOffice Document |
`tar` | TAR File |
`tar.bz2`, `tb2`, `tbz` | BZIP2 Compressed TAR File |
`tar.gz`, `tgz` | GZIP Compressed TAR File |
`tzp, zip.rae, zip.raes` | RAES Encrypted ZIP File |
`zip` | ZIP File |