Search code examples
javaantjar

Change the package of a JAR from the default package


I've downloaded a JAR file from my teacher's website containing some classes in the default package, and I'm thus unable to access them from inside a defined package.

I have read that the preferable solution is to repackage the JAR, changing the package name. However I have no idea how to go at it. The solution probably involves using Ant or Jar Jar, but I've no experience with either tool. I would love if someone coould point me in the right direction.

Thanks.


Solution

  • You need to change the sources and recompile then to change the package - simply moving the class files inside the jar (or outside) does not help.

    So ask your teacher to give you the sources (or to put the classes in a suitable package), or use a decompiler to do this yourself.