0

I am having .class (Dot-Class File) file ,inside this file some package name is available which I want to change but for these .class File I am not having related source code can anyone tell,How I will change the package name inside these dot class file ,is it possible or not

ashish
  • 11
  • 2
  • 1
    You know it's called just a "class file". You could decompile and recompile it, or straight up fiddle with the bytecode. Why do you need to change the package? – Kayaman Jun 17 '15 at 06:29

1 Answers1

1

There are multiple options

  1. Decompile the class using tools like jad, edit the decompiled file and then recompile it. This is not easy as you might have to have all dependencies properly packaged to recompile
  2. Edit .class file using a byte code editor like http://set.ee/jbe/ and replace occurrences of package name. This may end up causing some unexpected behaviours if the class depends on variables with default scope its original package.
  3. Use ant task jarJar (some details) and then achieve the repackaging.

    Disclaimer : I have not tried these ever. I would rather leave .class files alone. And if you are facing a conflict, it is better to think of some modularity solutions or maven modules or maven shaded jars.

Community
  • 1
  • 1
ring bearer
  • 20,383
  • 7
  • 59
  • 72