Marc Rasmussen
Marc Rasmussen

Reputation: 20555

Java program not functioning properly only when running the exported jar

I have a Java program (using JavaSE-1.6).

When i execute the program in eclipse there is no problem and i get the following:

How it should be

But when i export it to an executable jar and run it i get the following:

How it is

Has anyone ever experienced anything like this?

    Exception in thread "main" java.lang.NoSuchMethodError
        at org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStr
eam(RsrcURLConnection.java:43)
        at java.net.URL.openStream(Unknown Source)
        at sun.misc.URLClassPath$Loader.getResource(Unknown Source)
        at sun.misc.URLClassPath.getResource(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)

Upvotes: 0

Views: 875

Answers (2)

Aaron Digulla
Aaron Digulla

Reputation: 328614

The most common reason for this behavior is that you have two different versions of the same JAR on the classpath.

Depending on how you start your application, one or the other takes precedence and shadows the other.

If you use Maven, then the maven-duplicate-finder-plugin is for you.

Upvotes: 0

user591593
user591593

Reputation:

I encourage you to carefully read this page, it's just a very basic information about jar file: http://docs.oracle.com/javase/tutorial/deployment/jar/view.html

There is nothing special about jar file, in fact it is just an archive, like *.zip or *.rar. What java bin does is actually just to process the jar file based on the metadata inside and then run the classes inside.

A few things that you can do to debug:

  1. look into jar files, and check if all referenced files are complete: images, properties files, etc. And then check that the path is correctly referenced. Most of the times it's just a matter of interchange between slash and backslash.
  2. Check jar files mainfest in META-INF/MANIFEST.MF: if your program is using external libraries, you need to specify them in this file with the correct path!
  3. If your program does not have a logging system (e.g. log4j) then most probably the error log is printed on System.out stream (which is null/nowhere if you run the jar by double click-ing the executable jar. Hence, to look at system.out, you should try running your jar file from the shell command line: java -jar yourjarfile.jar

Upvotes: 1

Related Questions