0

I have a situation , I have jar files which contains com.somepackage.ABC.class file and I created in my local workspace com.somepackage.ABC.java (same name and package) rewrite existing functionality of ABC.java I am getting issue when I run my program it is always pickup jar ABC file not my local.

Sibidharan
  • 2,717
  • 2
  • 26
  • 54
  • Are you trying to modify the contents of the jar file? – Sibidharan Apr 18 '16 at 15:35
  • How are you repacking the JAR? Try some tools like http://jd.benow.ca which will help you to do it easily – Sibidharan Apr 18 '16 at 15:38
  • It's not recommended to have 2 versions of a class see http://stackoverflow.com/questions/8994147/what-are-the-implications-of-having-duplicate-classes-in-java-jar. Anyway what is your question ? – Jean-Christophe Blanchard Apr 18 '16 at 16:01
  • Hi Jean , same jar file has class which called ABC object as reference. I rewrite ABC class in my local , so I am trying to use new functionality. – Raman Singh Apr 19 '16 at 15:20

1 Answers1

0

As far as possible, you should remove the conflict in the package and name of the class. Simply use another class name (e.g. DEF) or another package name. There are ways to do this using mechanisms like services.

Assuming you must live with the conflict, your results, by default, are going to depend on the ClassPath with which the JVM is started. After you compile your local ABC.java to ABC.class in current folder (the actual class is in com/somepackage) then, you should give your classpath as: java -cp ".:path/to/foo.jar (on Unix) or java -cp .;path\to\foo.jar (on Windows), then your local class will take precedence over the the one in the JAR file.

Kedar Mhaswade
  • 4,535
  • 2
  • 25
  • 34
  • As it might be silly question , where should I add java -cp .;path\to\foo.jar. I am using tomcat 6 – Raman Singh Apr 19 '16 at 15:05
  • Oh, that was not apparent in your original question. See http://stackoverflow.com/a/1301458/437506. In that case, instead of the leading '.', you will need to use the path (top folder) where your version of `ABC.class` resides. – Kedar Mhaswade Apr 19 '16 at 16:24