Generate war file from tomcat webapp folder

前端 未结 4 1133
醉话见心
醉话见心 2020-12-12 13:06

I have a tomcat server working, and there I have a webapp folder my_web_app.

I didn\'t deploy the project; I only have that folder of that application (

相关标签:
4条回答
  • 2020-12-12 13:38

    Create the war file in a different directory to where the content is otherwise the jar command might try to zip up the file it is creating.

    #!/bin/bash
    
    set -euo pipefail
    
    war=app.war
    src=contents
    
    # Clean last war build
    if [ -e ${war} ]; then
        echo "Removing old war ${war}"
        rm -rf ${war}
    fi
    
    # Build war
    if [ -d ${src} ]; then
        echo "Found source at ${src}"
        cd ${src}
        jar -cvf ../${war} *
        cd ..
    fi
    
    # Show war details
    ls -la ${war}
    
    0 讨论(0)
  • 2020-12-12 13:40

    There is a way to create war file of your project from eclipse.

    First a create an xml file with the following code,

    Replace HistoryCheck with your project name.

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="HistoryCheck" basedir="." default="default">
        <target name="default" depends="buildwar,deploy"></target>
        <target name="buildwar">
            <war basedir="war" destfile="HistoryCheck.war" webxml="war/WEB-INF/web.xml">
                <exclude name="WEB-INF/**" />
                <webinf dir="war/WEB-INF/">
                    <include name="**/*.jar" />
                </webinf>
            </war>
        </target>
        <target name="deploy">
            <copy file="HistoryCheck.war" todir="." />
        </target>
    </project>
    

    Now, In project explorer right click on that xml file and Run as-> ant build

    You can see the war file of your project in your project folder.

    0 讨论(0)
  • 2020-12-12 13:44

    Its just like creating a WAR file of your project, you can do it in several ways (from Eclipse, command line, maven).

    If you want to do from command line, the command is

    jar -cvf my_web_app.war * 
    

    Which means, "compress everything in this directory into a file named my_web_app.war" (c=create, v=verbose, f=file)

    0 讨论(0)
  • 2020-12-12 13:49

    You can create .war file back from your existing folder.

    Using this command

    cd /to/your/folder/location
    jar -cvf my_web_app.war *
    
    0 讨论(0)
提交回复
热议问题