开发者

Change the package of a JAR from the default package

I've downloaded a JAR file from my teacher's website containing some cl开发者_Go百科asses 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.


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.


You can unjar/unzip them manually, create the package and jar them back using and IDE or from the command prompt like this. Also, take a look at the ANT documentation on Jar and Unjar which is quite comprehensive.


As @Piyush Instructed use the below command for creating a Jar file.
jar -cvf *.* Example.jar


If you are using eclipse, just unjar the source files into the source folder of a temporary project. Then, create a new project (the real project you will be working on), and under the java/src directory, create the package structure you want. Then it's just a simple matter of drag-n-dropping the source files from the temporary project into the correct packages in the real project. Eclipse will take care of changing the package declaration of each class for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜