如何使用命令行创建WAR文件? [英] How to create a WAR file using the commandline?

查看:151
本文介绍了如何使用命令行创建WAR文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了JBoss Developer Studio,可以通过鼠标右键项目>导出> WAR文件"创建WAR文件,但是我想使用命令行将项目导出到WAR文件.

I installed JBoss Developer Studio and it's possible to create a WAR file by "right mouse project > Export > WAR file" but I want to export my project to a WAR file using the commandline.

我已经安装了maven,这是Studio的要求之一,并且我读到可以使用maven生成WAR文件,但我需要一个名为pom.xml的文件.当我搜索我的工作区和项目时,缺少pom.xml.我可能需要手动创建pom.xml,但不确定如何.

I have maven installed which is one of the requirements of the Studio and I read that I can generate a WAR file using maven but I require a file called pom.xml. When I searched through my workspace and project, pom.xml was missing. I may need to manually create pom.xml but I'm unsure how to.

我的项目的目录树如下:

My directory tree for my project is the following:

Siesta
├── build
│   └── classes
├── src
└── WebContent
    ├── extjs
    ├── extjs-4.2.0
    ├── extjs-4.2.2
    ├── index.jsp
    ├── META-INF
    ├── siesta
    ├── tests
    └── WEB-INF

如何使用命令行为Maven/JBoss项目创建WAR文件?我使用Linux,宁愿不必创建pom.xml文件,但是如果没有其他方法,那么我将使用xml文件生成war文件.

How do I create a WAR file for my Maven / JBoss project using the command line? I use Linux and would prefer not having to create a pom.xml file but if there isn't another way, then I'll use the xml file to generate the war file.

所以jar是创建war文件的方法.我写了一个小脚本,它将为我为特定目录创建一个war文件.

So jar is the way to go to create a war file. I wrote up a tiny script that will create a war file for me for a specific directory.

#!/bin/bash
cd Siesta/WebContent/
jar -cvf ../../Siesta.war *
cd -

然后,如果您在ubuntu中的zip实用程序或存档管理器中打开war文件,则会看到此结构

Then if you open the war file in a zip utility or archive manager in ubuntu, you'll see this structure

    ├── extjs
    ├── extjs-4.2.0
    ├── extjs-4.2.2
    ├── index.jsp
    ├── META-INF
    ├── siesta
    ├── tests
    └── WEB-INF

我必须将CD放入要创建其烦人的war文件的目录中.我认为使用jar的-C选项可能会有更好的方法,但是当我使用"jar -cvf Siesta.war -C Siesta/WebContent *"时,结果并不相同.

I have to CD into the directory that I want to create a war file of which is kind of annoying. I think there may be a better way to do it using jar's -C option but when I used "jar -cvf Siesta.war -C Siesta/WebContent *" it didn't have the same result.

jar -cvf my-app.war myfolder/

为了使我的应用程序在TomCat上运行,我使用以下内容:

For my application to work on TomCat, I use the following:

cd Siesta/WebContent
jar -cvf Siesta.war *

推荐答案

好的,这里是一个已经存在的SO,它具有创建战争文件的几种可能性:

Alright here is a already existing SO with a couple of possibilities on how to create a war file: How to create war files.

与任何其他构建方案相比,我个人更喜欢Maven-由于我是从ANT迁移而来的,所以我最初并不喜欢Maven,但是在文档中花了一两天的时间后:

I personaly prefer Maven over any other build scenario - Since i migrated from ANT i did not like Maven in the first place but after investing like a day or two into the documentations: http://maven.apache.org/pom.html i started to love it. In your case all you need is refactor your project to meet the maven standard file structure and create a minimum Maven project (a.k.a. pom.xml file) for your sources that has the packaging war instead of the default jar.

如果您只想使用控制台,并且不使用JDK提供的构建助手,则可以使用以下方法创建战争:

If you want to stick with the console only and dont use any build helpers beside the ones delivered by the JDK you can create your war with something like this:

jar cvf my-app.war

看看这个: https://docs.oracle .com/javase/tutorial/deployment/jar/build.html 以获得受支持选项的完整参考.

Have a look at this: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html for a complete reference of the supported options.

(注意:基于Java的Web应用程序上下文中的战争"遵循标准格式: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html ,而技术上的".war"文件与已重命名的ZIP压缩文件夹相同到".zip".)

(Note: A "war" in the context of java based web applications follows a standard format: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html while the technical ".war" file is just the same as a ZIP compressed folder renamed to ".zip".)

(还请注意,我真的会花时间与Maven联系,因为在此之后,您知道了一个严肃的构建工具,并且能够以标准方式创建jarearwar等.过程).

(Also note i would realy take the time to get in touch with maven since after that you know about a serious build tool and will be able to create jar, ear, war etc. in a standard process).

这篇关于如何使用命令行创建WAR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆