Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Generate a War file

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have an application with some servlets and some JSPs. My Jsps are located under C:\tomcat50-jwsdp\webapps\ROOT\FullExample and my Servelts are located under C:\tomcat50-jwsdp\webapps\ROOT\WEB-INF\classes\FullExample and the web.xml is located under C:\tomcat50-jwsdp\conf

How to generate a war file for FullExample.

Thanks a lot
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A WAR file is just a JAR file, so you can create a WAR file with the jar tool that you get with the JDK. The JAR file must have a specific structure. The JSPs should be in the root of the JAR, the deployment descriptor (web.xml) must be in a directory WEB-INF inside the JAR, and servlet and other classes must be in WEB-INF/classes.

Found with Google: Manually Creating a Simple Web ARchive (WAR) File
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maha Hassan:
Dear All,

I have an application with some servlets and some JSPs. My Jsps are located under C:\tomcat50-jwsdp\webapps\ROOT\FullExample and my Servelts are located under C:\tomcat50-jwsdp\webapps\ROOT\WEB-INF\classes\FullExample and the web.xml is located under C:\tomcat50-jwsdp\conf

How to generate a war file for FullExample.

Thanks a lot


Well, first of all, you should't have your application under ROOT, you should move it to directly under webapps. And also, why is your web.xml under conf? That web.xml is meant for ALL applications under Tomcat and you should have your own web.xml under /WEB-INF/web.xml.

To answer your question, a WAR is basically a JAR is basically a ZIP. So, to hack it, you could simply ZIP up the correct folder structure ( don't ZIP the containing folder, just the contained directories ) and rename it with an extension .war. Or you could JAR it and rename it .war. Or you could use an IDE to build it for you.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the links I posted?
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the link but I do not get the
The static HTML files and JSPs are stored in the top level directory.
Does this mean directly under WEB-INF I will have all jsp Files

And also
jar cvf mywar.war WEB-INF {related top-level files or directories}
What are the related top-level files or directories. And does this example assumes that there is a folder WEB-INF/classes/mywar and when I typt this I am standing at the parent of WEB_INF ?

Thanks
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make my question more clear.
Under WEB-INF I will have a folder containing the jsp's (Project)
a web.xml with servlets mapping
a folder underclasses with the servlets and jsps(Project).

Then I will go to the parent of WEB-INF and type the command
jar cvf Project.war WEB-INF
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maha Hassan:
Does this mean directly under WEB-INF I will have all jsp Files

No. The JSP files must be in the root of the WAR file, not under the WEB-INF directory. The WEB-INF directory is a subdirectory in the WAR file.
Example:


C:\MyProject> jar cvf ..\mywebapp.war *.*
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic