Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am running my java program but on executing it gives me following error. before it was running fine but now it's throwing following error. I checked my class path, path in environment variable all are correct.

Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:114)
        at java.util.jar.JarFile.<init>(JarFile.java:135)
        at java.util.jar.JarFile.<init>(JarFile.java:72)
        at sun.misc.URLClassPath$JarLoader.getJarFile(URLClassPath.java:646)
        at sun.misc.URLClassPath$JarLoader.access$600(URLClassPath.java:540)
        at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:607)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:599)
        at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:583)
        at sun.misc.URLClassPath$3.run(URLClassPath.java:333)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.misc.URLClassPath.getLoader(URLClassPath.java:322)
        at sun.misc.URLClassPath.getLoader(URLClassPath.java:299)
        at sun.misc.URLClassPath.getResource(URLClassPath.java:168)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: com.sun.tools.javac.Main.  Program will exit.
                By the way, why are you referencing javac when you are running the program? Are you trying to compile a class in the runtime?
– randominstanceOfLivingThing
                Nov 1, 2012 at 13:59
                @beny23 You should post your comment as an answer as I believe this is the cause of the problem.  I found com.sun.tools.javac in my JDK (tools.jar) and not in my JRE.
– HeatfanJohn
                Nov 1, 2012 at 14:03

The start of the stacktrace is this:

Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:114)

The UnsatisfiedLinkError is thrown when you attempt to call a native method that has not been resolved to a method in the corresponding native library. The rest of the message tells us that the method at fault has the signature:

long java.util.zip.ZipFile.open(String, int, long)

and that meshes with the top frame of the stack trace ... and the fact that Java's ZipFile code is known to use a native library for the heavy lifting.

The fact that it has gotten this far means that the JVM has found the native library and loaded it. But apparently, the load didn't resolve this overload of the native open method. That can only mean one thing: that the version of the ZipFile class on the bootclasspath does not match the native library.

We cannot make any definite conclusions about whether this is a JDK or a JRE, but it seems likely that it is a JDK ... unless the OP is trying to call the Java compiler in a strange way. (The "could not find the main class: com.sun.tools.javac.Main" message probably means that the JVM could not load the class ... because of the UnsatisfiedLinkError breakage.)

Either way, JDK versus JRE is not the immediate problem. The real problem is a mismatch between the "rt.jar" on the JVM's bootclasspath, and the native libraries.

The question asks:

how to solve this then?

It depends on what exactly you did to get this error.

  • What command did you run?
  • What were the command line options and arguments?
  • Have you been "messing around" with your JRE / JDK installation?
  • Are you trying to use the "rt.jar" file from one installation in another one?
  • Excellent elaboration, thank you! One question, how did you translate java.util.zip.ZipFile.open(Ljava/lang/String;IJ)J to long java.util.zip.ZipFile.open(String, int, long)? Is I shorthand for int and J shorthand for long? BTW, I found on the web some source code for ZipFile and I see the method declaration for open which matches your referenced signature: private static native long open(String name, int mode, long lastModified); – HeatfanJohn Nov 1, 2012 at 17:27

    It means your rt.jar is for a different version of Java as your JVM.

    I would ensure that you don't have a rt.jar in your boot class path and your JRE is installed correctly.

    Could not find the main class: com.sun.tools.javac.Main. Program will exit.

    When a class fails to load due to some low level error, it reports that the class could not be found.

    I thought the cause of the problem was using ZipFile from native code. Are you saying you believe javac is the cause of the error? If so can you say why? – Peter Lawrey Nov 1, 2012 at 14:08 +1 Hummm ... good point! You are saying that a valid java.util.zip.ZipFile.open which I have verified is in (rt.jar) should not attempt to call com.sun.tools.javac.main which is not in rt.jar. I focused on the immediate cause of the error as opposed to the true issue which is that the run time java.util.zip.ZipFile.open should not invoke a JDK component. I'm now glad that I didn't -1 this answer! – HeatfanJohn Nov 1, 2012 at 14:17 I am saying java.util.zip.ZipFile.open(Native Method) in native code is trying to call java.util.zip.ZipFile .open(Ljava/lang/String;IJ)J which would exist if the JVM and the rt.jar were the same. – Peter Lawrey Nov 1, 2012 at 15:48 Does Native Method for Java mean machine dependent platform code such as would be found in a DLL on Windows or ".so" Shared Object specification of ELF (Executable and Linking Format) on Linux? – HeatfanJohn Nov 1, 2012 at 16:04 yes, and it uses something like reflection if it is to call back into Java which can fail like this if the method doesn't exist. – Peter Lawrey Nov 1, 2012 at 16:13

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.