Java 从tomcat webapp文件夹生成war文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16342075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:24:24  来源:igfitidea点击:

Generate war file from tomcat webapp folder

javatomcat

提问by eLRuLL

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

我有一个 tomcat 服务器在工作,在那里我有一个 webapp 文件夹my_web_app

I didn't deploy the project; I only have that folder of that application (as TOMCAT_DIR/webapps/my_web_app).

我没有部署项目;我只有那个应用程序的文件夹(如TOMCAT_DIR/webapps/my_web_app)。

What I need is a WAR file. How can I create a .warfile from this webapp?

我需要的是一个 WAR 文件。如何.war从此网络应用程序创建文件?

采纳答案by Ketan

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

您可以从现有文件夹创建 .war 文件。

Using this command

使用这个命令

cd /to/your/folder/location
jar -cvf my_web_app.war *

回答by Charu Khurana

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

就像创建WAR项目文件一样,您可以通过多种方式(从 Eclipse、命令行、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)

这意味着,“将此目录中的所有内容压缩到名为 my_web_app.war 的文件中”(c=create, v=verbose, f=file)

回答by nmkyuppie

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

有一种方法可以从 eclipse 创建项目的 war 文件。

First a create an xml file with the following code,

首先使用以下代码创建一个xml文件,

Replace HistoryCheck with your project name.

用您的项目名称替换 HistoryCheck。

<?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 xmlfile and Run as-> ant build

现在,在项目资源管理器中右键单击该xml文件并运行 as-> ant build

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

你可以在你的项目文件夹中看到你的项目的war文件。

回答by Gary Davies

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.

在内容所在的不同目录中创建 war 文件,否则 jar 命令可能会尝试压缩它正在创建的文件。

#!/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}