Seeing contents of war file without extracting
The t
option to the command line jar
program will list the contents of a jar (or war) file, e.g.:
$ jar tf the-file.war
Extract/See content of a specific file inside a .war file
jar
has x
option for that:
$ jar -help 2>&1 | grep extract
-x extract named (or all) files from archive
Let's try it:
$ jar tvf target/my.war | grep test-data
1811 Tue Jun 21 19:34:50 CEST 2016 WEB-INF/classes/test/spring/test-data.properties
$ jar xvf target/my.war WEB-INF/classes/test/spring/test-data.properties
inflated: WEB-INF/classes/test/spring/test-data.properties
$ ls -l WEB-INF/classes/test/spring/test-data.properties
-rw-rw-r--. 1 coder coder 1811 Jun 21 19:34 WEB-INF/classes/test/spring/test-data.properties
How to extract only one file from war file?
The -j
flag is exactly what you need:
unzip -j test.war "*test.properties*"
From the docs:
-j
junk paths. The archive's directory structure is not recreated; all
files are deposited in the extraction directory (by default, the
current one).
One liner for listing contents of file within war file
Is this what you are looking for?
unzip -qc SOME_WAR_FILE.war META-INF/MANIFEST.MF
See the previous answer here.
How to extract .war files in java? ZIP vs JAR
If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.
The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.
It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.
How do I access a text file from within my war
Check out ServletContext.getResourceAsStream(). Here is an example.
Related Topics
How to Detect Out-Of-Memory Segfaults
Case Statement in a While Loop, Shell Scripting
How to Disable The Gnome Desktop Screen Lock
Mq Explorer - Could Not Load Swt Library
Make Command Not Working in Ns 2.35
Perf: Strange Relation Between Software Events
Code for Wait_Event_Interruptible
How to Enter Private Key Password with Ansible
How to Enable Vt-X/Amd-V in Aspire V5-122P Bios
How Does Apparmor Handle Linux-Kernel Mount Namespaces
Bluetooth Over Uart Using Hciattach
Gitlab-Ci Alpine Image: Host Key Verification Failed
Vue Npm Run Serve Failed to Load Resource: Net::Err_Content_Length_Mismatch
How to Source a Simple Bash Script
Creating Filename_$(Date %Y-%M-%D) from Systemd Bash Inline Script
How to Continously Run a Unix Script in Background Without Using Crontab.