aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Building a .WAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Building a .WAR file" Watch "Building a .WAR file" New topic
Author

Building a .WAR file

David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

At the moment I wimp out and let eclipse generate a .WAR file for me. However I would like to have a script to do this. I have tried to run a command like the following in the base project directory of my eclipse web project but the resultant .war file structure is not the same as the one that eclipse creates for me and does not work - page not found errors etc.

jar cvf archiveName.war .

For example the .jsp file physically reside in my webcontent directory within the eclipse directory structure. However when eclipse creates the .war file those .jsp files appear in the root.

When I run the command above they remain in a subdirectory.

So do I need to re-jig my eclipse project or do something different for the jar command ?

Thanks in advance

Dave
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 365
Hi Devid,

You can do this by ANT.


Thanks,
Shailesh
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

Will that overcome the problems I am experiencing with the JAR command or is it just another way of doing the same. I am aware of ANT but never used it personally so I dont know if it would overcome the structural "path" issues I have with the resultant .WAR file.

Thanks

Dave
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

If it would help anyone understand my problem the source for my project can be downloaded from my open source project www.commander4j.com - all you want it b4web.zip

The b4web.war file on the download page has been created by using the Eclipse IDE export to WAR function rather than any automated build script.

Dave
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

I am getting closer to understanding the problem - but not the solution.

When I hunt around in the Project Properties within Eclipse I see this page called a Web Deployment Assembly (see attached screen dump). If shows how the physical project directory structure is mapped (changed) when building a .WAR file from the Eclipse IDE.

When I run the jar command this mapping does not seem to happen and as such I end up with an invalid structure.

So - how do I replicate what Eclipse is doing when it builds the .WAR file for me ?

Thanks

Dave



[Thumbnail for wda.png]

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

You really should look into Ant or Maven to do this for you. If you insist on just running jar from the command line, then you should first copy all of the files you need into a single directory (preferably not within the existing Eclipse project directory structure ) that matches the desired war contents, and then jar that directory.


JBoss In Action
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

OK - I will look at ANT then - can you recommend a web link or book that would deal with the type of thing I'm trying to do. I don't seem to know the correct key words to find any useful examples. This kind of build which needs to re-arrange the structure of the target file must be very common ?

Is this re-arrangement of directories something unique to how eclipse works ?

Thanks

Dave
David Garratt
Ranch Hand

Joined: Aug 08, 2003
Posts: 187

I see I can export an Ant build file from eclipse for this web project - but it does not seem to generate a .war file for me - unless I am doing it wrong.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

using ant to create a war file
sco phone
Greenhorn

Joined: Mar 21, 2011
Posts: 4
Thanks,everyone!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Building a .WAR file
 
Similar Threads
creating WAR file in Eclipse IDE
any good free Java IDE + debugger
Eclipse problem regarding M2Eclipse/integrated web server
How do I install JGoodies Look and Feel??
Problem with mvn archetype using Eclipse plugin