How to unpackage and repackage a WAR file

后端 未结 8 1065

I have a WAR file. I would like to open it, edit an XML file, remove some jars and then re-package it.

I used WINRAR to open the WAR file and I removed some Jars and

相关标签:
8条回答
  • 2020-12-02 12:44

    This worked for me:

    mv xyz.war ./tmp
    cd tmp
    jar -xvf xyz.war
    rm -rf WEB-INF/lib/zookeeper-3.4.10.jar
    rm -rf xyz.war
    jar -cvf xyz.war *
    mv xyz.war ../
    cd ..
    
    0 讨论(0)
  • 2020-12-02 12:45

    Adapting from the above answers, this works for Tomcat, but can be adapted for JBoss as well or any container:

    sudo -u tomcat /opt/tomcat/bin/shutdown.sh
    cd /opt/tomcat/webapps
    sudo mkdir tmp; cd tmp
    sudo jar -xvf ../myapp.war
    #make edits...
    sudo vi WEB-INF/classes/templates/fragments/header.html
    sudo vi WEB-INF/classes/application.properties
    #end of making edits
    sudo jar -cvf myapp0.0.1.war *
    sudo cp myapp0.0.1.war ..
    cd ..
    sudo chown tomcat:tomcat myapp0.0.1.war
    sudo rm -rf tmp
    sudo -u tomcat /opt/tomcat/bin/startup.sh
    
    0 讨论(0)
  • 2020-12-02 12:52

    I am sure there is ANT tags to do it but have used this 7zip hack in .bat script. I use http://www.7-zip.org/ command line tool. All the times I use this for changing jdbc url within j2ee context.xml file.

    mkdir .\temp-install
    c:\apps\commands\7za.exe x -y mywebapp.war META-INF/context.xml -otemp-install\mywebapp
    ..here I have small tool to replace text in xml file..
    c:\apps\commands\7za.exe u -y -tzip mywebapp.war ./temp-install/mywebapp/*
    rmdir /Q /S .\temp-install
    

    You could extract entire .war file (its zip after all), delete files, replace files, add files, modify files and repackage to .war archive file. But changing one file in a large .war archive this might be best extracting specific file and then update original archive.

    0 讨论(0)
  • 2020-12-02 12:53

    copy your war file to /tmp now extract the contents:

    cp warfile.war /tmp
    cd /tmp
    unzip warfile.war
    cd WEB-INF
    nano web.xml (or vim or any editor you want to use)
    cd ..
    zip -r -u warfile.war WEB-INF
    

    now you have in /tmp/warfile.war your file updated.

    0 讨论(0)
  • 2020-12-02 12:56

    you can update your war from the command line using java commands as mentioned here:

    jar -uvf test.war yourclassesdir 
    

    Other useful commands:

    Command to unzip/explode the war file

    jar -xvf test.war
    

    Command to create the war file

    jar -cvf test.war yourclassesdir 
    

    Eg:

    jar -cvf test.war *
    jar -cvf test.war WEB-INF META-INF
    
    0 讨论(0)
  • 2020-12-02 12:57

    Maybe, you have modified the structure of the war or deploying it on a different server version. Checkout these links Error deploying war into JBoss AS 7 (domain mode): "Failed to process phase STRUCTURE of deployment" and https://community.jboss.org/thread/199387?start=0&tstart=0&_sscc=t

    0 讨论(0)
提交回复
热议问题