Question

I have two .class file with the same name and same package in two different .jar file

First jar:
enter image description here

Second jar:
enter image description here

When i run the program from eclipse i haven't problem, eclipse use the first .class file (i must use the first . class, i don't need the second .class, i want exclude it).

When i export runnable .jar i saw that is executed the second .class file and then i have NoSuchMethodError exception, because the second .class is different from the first.

How can i use always the first .class and exclude the second? I don't need the second .class, but i need other class from his library.

Était-ce utile?

La solution

Java loads classes from classpath that is defined dynamically when you are running application in eclipse and is controlled by property Class-Path in file MANIFEST.MF located under META-INF in you jar file.

So, first open jar file using any ZIP tool and take a look on manifest. Try to change the order of jar files into manifest and run again. I hope this will help.

BUT this is extremely bad that your alive-matchmarker.jar contains file that it should not contain. I do not know what library is it but is there a chance that they have other distribution that does not contain their own dependencies? Or probably try to find other version of this library. The worse thing that can be is if you have different versions of the same class in your classpath: the behavior of your application can be buggy and unpredictable as a result of this duplication because you can never know what version of class is used now.

Autres conseils

Do not import the whole package like

import org.mindswap.*;

You can import specific class you want from any specific package like

import org.mindswap.wsdl.WSDLTranslator;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top