简体   繁体   中英

How to create jar file from existing jar file?

I have not worked on java till now.... But i need to include the jar file into my project.

I have one jar created already with me. But i need to update this jar file. I don't have source of those project.

It has folder structure like follow

1. folder which has .class file.
2. com folder
3. de folder
4. META-INF folder contains MANIFEST.INF file and Maven folder
5. org folder
6. config.properties
7. abc.builds.properties

I need to update config.properties and create new jar file.

Can anybody help me in this?

The procedure is roughly this:

  1. Create a temporary directory and "cd" to it.
  2. Use "jar xf file.jar" to extract the JAR file.
  3. Add, edit, remove files
  4. Use "jar cf new-file.jar .... " to create the new JAR file.

The better way than integrating the classes of the other jar within your jar is to declasr within your jar that you want to use the other jar.

The procedure is roughly this:

  • Create a file with name MANIFEST.MF in a the sub folder META-INF as child of src/ .
  • add a line
    Class-Path = theOther.jar
  • when creating the jar make sure this file (and the folder) are included.

for mor information see here: http://docs.oracle.com/javase/tutorial/deployment/jar/

The Jar tool provides a u option which you can use to update the contents of an existing JAR file by modifying its manifest or by adding files. Command for adding files has this format:

jar uf jar-file input-file(s)

Existing file will get update.

Look here For more Detail and Click here

I think Stephen C has given the solution. In fact you should

  1. Unzip your jar file with the Jar utility provided within the JDK and then
  2. Update your config.properties then
  3. Zip all the project with Jar utility and that's it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM