How to create a WAR file using the commandline?

不羁岁月 提交于 2019-11-29 13:19:12
JBA

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

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.

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

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

(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".)

(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).

If this is a Maven project, then open your console, navigate to where the pom.xml file is and then run:

mvn package

It will create the {artifactId}-{version}.war file under ${basedir}/target directory. This assumes that your packaging POM element is set to war in your pom.xml file.

<project ...>
    ...
    <packaging>war</packaging>
    ...
</project>

Some of the valid packaging values are jar, war, ear and pom. If no packaging value has been specified, it will default to jar.

More details here and here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!