Suppose I have have a java project myProject
and am using an external library jar (someJar.jar
), which has a class com.somepackage.Class1.class
.
Now I find an updated version of Class1.java
which fixes a bug in the original jar.
I include the new Class1.java
in my source code under package com.somepackage
When I build the project (e.g., using Netbeans), there is a dist\myProject.jar
which contains the classcom.somepackage.Class1.class
and a dist\lib\someJar.jar
which also contains a class with the same name.
When I run the file (e.g, using java -jar dist\myProject.jar
), the new version of Class1.class
is used (as I want).
How does Java decide which class file to run in case of such duplicates? Is there any way I can specify precedence ?
Is there any 'right' way to avoid such clashes?
In Proguard, when I try to compress my code, I get a duplicate class
error. How do I eliminate this?
Java decides which one to use based on the order of the classpath. List yours first and you'll be fine.
The "right" way would be to fix the orignal source, but sometimes that's not always an option.
I haven't used ProGuard, but I have re-jarred libaries before that had duplicate classes. The solution in my case was to tell Ant to ignore duplicate classes. I would assume ProGuard would have that support too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With