47

What is the easy way to make war file?

My project is working when i right click run on server, but i want to deploy on tomcat server. I have installed m2clipse but it gave me an error.

  1. Is maven compulsory to make war file?
  2. Do i need special directory structure to make war with eclipse?

    Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project testing2: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1] [ERROR]

vbence
  • 20,084
  • 9
  • 69
  • 118

1 Answers1

91

File -> Export -> Web -> WAR file

OR in Kepler follow as shown below :

enter image description here

KNU
  • 2,560
  • 5
  • 26
  • 39
Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
  • I believe you can also export a jar file and simply give it a .war extension – Chris Thompson Feb 24 '11 at 17:20
  • 6
    Exporting a jar and renaming it will most definitely not work. While both jar and war are basically zip archives, their contents are drastically different. – Konstantin Komissarchik Feb 24 '11 at 17:21
  • The only difference is the presence of the WEB-INF directory and the location of the binary output. Eclipse can be configured to generate this properly via the jar export functionality. – Chris Thompson Feb 24 '11 at 18:22
  • 4
    That's not the only difference. A WAR has "web content" in addition to descriptors and java classes. The export WAR wizard works with the Eclipse Dynamic Web Project than the asker is undoubtedly using to make sure that the web content and all the other pieces get properly packaged into the WAR. – Konstantin Komissarchik Feb 24 '11 at 19:39
  • 12
    My version of Eclipse (Kepler, 20130614-0229) has neither "Web" nor "WAR file" as an export option. – Dan Jameson Jan 31 '14 at 14:07
  • @DanJameson in the `Project Explorer` menu `Right Click` on the Web project to find `Export` -> `WAR File`. Thanx – KNU Jun 08 '14 at 10:27
  • @Dan Jameson - Is your project a '(Dynamic) Web Project' ? – KrishPrabakar May 21 '15 at 07:42
  • @DanJameson My Eclipse (Neon) also didn't have the option to export to "Web / WAR file", until I installed "Eclipse Java EE Developer Tools". – Cos64 Mar 04 '17 at 18:46