0

Quick question (sorry struggling with time)

How can I add any file from my file system under WEB-INF/classes folder in a jar file? I am trying this with jar command but it copies a file in a jar with its absolute path meaning if I create a file at E:\folder1\WEB-INF\classes folder and try to add it to a jar it creates folder1/WEB-INF/classes folder inside the jar and places the file into it.

I used jar command as below

jar -uvf E:\folder1\sample.jar E:\folder1\WEB-INF\classes\pkfe

qwerty
  • 2,294
  • 3
  • 26
  • 48

1 Answers1

1

you need to specifiy the -C-switch and alter the file-argument like so:

jar -uvf E:\folder1\sample.jar -C E:\folder1 WEB-INF\classes\pkfe

This makes the command run within E:\folder1 and include the files relative from that location

You can also add entire folders this way:

jar -uvf -uvf E:\folder1\sample.jar -C E:\folder1 .

The . tells the command to add everything at the location of the working directory (E:\folder1). You need to move your sample.jar to somewhere else, otherwise you would softlock the command, as it would be adding itsself to itsself into eternity...

Several specific files within a folder would work like this

jar -uvf E:\folder1\sample.jar -C E:\folder1 WEB-INF\classes\pkfe -C E:\folder1 WEB-INF\classes\secondFile.dat -C E:\folder1 org\blupp\blah\thirdFile.class

Source: jar -?

Pingger Shikkoken
  • 313
  • 1
  • 4
  • 10
  • Thanks!!! It worked like a charm. Also, how can I pass multiple files in ```WEB-INF\classes``` with names as it only worked for me on passing the -C switch pattern again for a second file I was trying to include? – qwerty Feb 13 '21 at 11:48
  • Thanks for the update!!! I was creating 3 files post build which I wanted to add in the jar. For this I had to specify them with their ```-C``` switches separately (as you also mentioned) and it worked. – qwerty Feb 14 '21 at 13:43