aspose file tools*
The moose likes Tomcat and the fly likes How to Generate a War file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to Generate a War file" Watch "How to Generate a War file" New topic
Author

How to Generate a War file

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
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

Joined: Aug 16, 2005
Posts: 14268
    
  21

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


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
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

Joined: Aug 16, 2005
Posts: 14268
    
  21

Did you look at the links I posted?
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
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

Joined: Aug 02, 2005
Posts: 133
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

Joined: Aug 16, 2005
Posts: 14268
    
  21

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 *.*
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Generate a War file