Question

I have a JAR file with following structure:

com
-- pack1
   -- A.class
-- pack2
   -- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.class

When I try to read, extract or rename pack2/AA...AA.class (which has a 262 byte long filename) both Linux and Windows say filename is too long. Renaming inside the JAR file doesn't also work.

Any ideas how to solve this issue and make the long class file readable?

Was it helpful?

Solution 2

java.util.jar can handle it:

try {
    JarFile jarFile = new JarFile("/path/to/target.jar");
    Enumeration<JarEntry> jarEntries = jarFile.entries();
    int i = 0;
    while (jarEntries.hasMoreElements()) {
        JarEntry jarEntry = jarEntries.nextElement();
        System.out.println("processing entry: " + jarEntry.getName());
        InputStream jarFileInputStream = jarFile.getInputStream(jarEntry);
        OutputStream jarOutputStream = new FileOutputStream(new File("/tmp/test/test" + (i++) + ".class")); // give temporary name to class
        while (jarFileInputStream.available() > 0) {
            jarOutputStream.write(jarFileInputStream.read());
        }
        jarOutputStream.close();
        jarFileInputStream.close();
    }
} catch (IOException ex) {
    Logger.getLogger(JARExtractor.class.getName()).log(Level.SEVERE, null, ex);
}

The output willbe test<n>.class for each class.

OTHER TIPS

This pages lists the usual limits of file systems: http://en.wikipedia.org/wiki/Comparison_of_file_systems

As you can see in the "Limits" section, almost no file system allows more than 255 characters.

Your only chance is to write a program that extracts the files and shortens file names which are too long. Java at least should be able to open the archive (try jar -tvf to list the content; if that works, truncating should work as well).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top