2

I would like to ask a question if there is a way to copy a file(i.e. an image) to a .jar file, because i want to deploy a program and i created folders along with the source codes(they are in the same location as the source codes) and the folders are inside the jar file (i used Netbeans to create the jar file)..... Now what i want is i would like to copy files choosen by a JFileChooser to the folders inside the jar file???? Any idea is heartily accepted..!!! Thanks in advance????

P.S.: I already tried searching the net for answers but all they know is how to copy the file inside the jar file to another directory......

New to Programming
  • 133
  • 1
  • 3
  • 13

2 Answers2

1

Suppose that you want to add the file images/image1.gif to the JAR file.

jar uf <fileName>.jar images/image1.gif

To change the directory use -c

jar uf <fileName>.jar -C 

in this command

jar uf jar-file input-file(s)

In this command:

The u option indicates that you want to update an existing JAR file.
The f option indicates that the JAR file to update is specified on the command line.
jar-file is the existing JAR file that's to be updated.
input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

Related Docs

Raj
  • 942
  • 1
  • 7
  • 12
0

A JAR file is a ZIP compressed file.

See this S.O. answer for a solutiion to add files to an exisiting ZIP archive: Appending files to a zip file with Java

Community
  • 1
  • 1
Andrea Colleoni
  • 5,919
  • 3
  • 30
  • 49