Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Ant, Maven and Other Build Tools and the fly likes How to Make Executable War File for Web App Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to Make Executable War File for Web App" Watch "How to Make Executable War File for Web App" New topic
Author

How to Make Executable War File for Web App

Tumaini Kilimba
Greenhorn

Joined: Nov 15, 2006
Posts: 16
Dear all,
Am wondering how I can create an executable war file for a maven web application?

Thanks in advance,
joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62

executable war

i hope you mean .war and not .exe
<packaging>war</packaging> in your pom.xml should do it.

Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

In my understanding a war-file is exclusively for Java Web Application Servers (e.g. Tomcat). In a way they are already 'executable' because when you deploy a war-file on such a server it will auto-unzip/install/configure/whatever the packaged web application.

It is not possible - not to my knowledge at least - to make it executable like you have an executable jar or like certain file extensions (exe, ...) make a file executable on the operating system.

Cheers,
Wim
Tumaini Kilimba
Greenhorn

Joined: Nov 15, 2006
Posts: 16
Wim Vanni wrote:In my understanding a war-file is exclusively for Java Web Application Servers (e.g. Tomcat). In a way they are already 'executable' because when you deploy a war-file on such a server it will auto-unzip/install/configure/whatever the packaged web application.

It is not possible - not to my knowledge at least - to make it executable like you have an executable jar or like certain file extensions (exe, ...) make a file executable on the operating system.

Cheers,
Wim


There seems to be enough on google to suggest that executable war files are possible, e.g Executable WAR...

Am I barking up the wrong tree?
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

holding an embedded servlet container


That would do the trick of course. I just learned something new :-)

I have - obviously - no experience and I guess you're best bet is to try and learn from those (few?) resources you can find on the web and maybe get in contact with the authors of those articles.

Good luck!
Wim
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5837
    
    7

If you examine an existing executable war file, such as the Jenkins war file, you will notice that it has the attributes of both an executable JAR file and a standard WAR file. Thus if you run it via "java -jar jenkins.war" it runs the enbedded Jetty(?) servlet engine with Jenkins pre-defined. Otherwise, if you deploy it to your favorite app server, it deploys like a standard WAR file.


JBoss In Action
Tumaini Kilimba
Greenhorn

Joined: Nov 15, 2006
Posts: 16
Peter Johnson wrote:If you examine an existing executable war file, such as the Jenkins war file, you will notice that it has the attributes of both an executable JAR file and a standard WAR file. Thus if you run it via "java -jar jenkins.war" it runs the enbedded Jetty(?) servlet engine with Jenkins pre-defined. Otherwise, if you deploy it to your favorite app server, it deploys like a standard WAR file.


Ok... so what are you suggesting I should do, please?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

I think there's some confusion here in that the desired goal isn't actually a product that can be executed either as a JAR or a WAR, but just a plain old WAR to execute in a server. So we don't need to worry about a dual-purpose WAR file. Which is good, since the classpaths for JARs and WARs are just different enough to be annoying.

If you setup the POM to product a WAR and then run "mvn clean compile war:war" that will build a deployable (executable) WAR in the project's target directory. Or, use the more general goal: "mvn clean package". Clean is optional, but it ensures that your source actually can build the output and it doesn't take that long to do.

It's not true that the process of deploying a WAR unzips the WAR. Yes, in a lot of servers, that does happen, but not in all of them or all of the time. When Tomcat unzips a WAR, the output is known as an "exploded WAR", but you can tell Tomcat not to explode WARs if you want. The J2EE standard doesn't say anything about exploding WARs - as far as it's concerned, the WAR deployed into a J2EE container is always zipped up.


Customer surveys are for companies who didn't pay proper attention to begin with.
Tumaini Kilimba
Greenhorn

Joined: Nov 15, 2006
Posts: 16
Tim Holloway wrote:I think there's some confusion here in that the desired goal isn't actually a product that can be executed either as a JAR or a WAR, but just a plain old WAR to execute in a server. So we don't need to worry about a dual-purpose WAR file. Which is good, since the classpaths for JARs and WARs are just different enough to be annoying.



No, I actually DO want to create a war which is executable. Maybe a bit of background is in order... I have created a GWT application for data collection of community health data and I want it to run on a Pocket PC, and/or Android Tablet. The pocket PC can connect and use the application by opening a browser and typing in the appropriate URL of the application (in this case the application is running on a server somewhere, and the pocket PC is just a "dummy terminal". However there will be occasions when there will be no internet connectivity as the setting is rural communities in developing countries, where internet connectivity is a luxury), and on those occasions it would be better if the application ran locally on the Pocket PC or Android Tablet, which would consequently require a web server to serve up the pages on these devices. If I could embed the web server in the war and make the war executable, I can run the application without installing of web server on the device.

Feel free to advise me of alternative ways I can achieve my goal, but at the moment am stuck on executable war file.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

Here the poster doubts it's possible to run Tomcat on Android, period. Another thread seems to say the same and advices the use of jetty but also has some warnings. Battery consumption by such an application and consumption of other resources might make this a difficult task to achieve.

Now you've provided some more detail, I can see what you're trying to do and why but my guess is you're at the moment perhaps better of with doing a similar thing on a netbook or tablet. Or make a client app that is not webbased for those cases where there's no internet connection to be found.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

A "Pocket PC" generally refers to one running mobile Windows, and since Microsoft hates Java, simply getting Java running on a Pocket PC can be a challenge, especially now that IBM doesn't seem to be plugging the J9 JVM for that platform.

I presume from what's been said, you're also tracking this thread: http://www.coderanch.com/t/542426/tools/Novice-Maven-User#2461526, wherein I get nit-picky about the term "executable WAR". The same general process would apply to what's wanted here, but as has been observed, putting a webserver on a mobile device has its extra challenges.

Myself, I'd probably just write a native Android app that opportunistically contacts a web server via REST or Web Services when it can. Less work, smaller footprint.

Tumaini Kilimba
Greenhorn

Joined: Nov 15, 2006
Posts: 16
Tim Holloway wrote:

Myself, I'd probably just write a native Android app that opportunistically contacts a web server via REST or Web Services when it can. Less work, smaller footprint.



I agree with you here, except that in our context, am not developing just 1 app for data collection surveys, they can be as many as 3 a month, and so when I started playing with Spring Roo and realised how quickly you can go from concept to working app in just a few minutes, it interested me, as it would drastically reduce the amounts of time spent on all these various apps,and as we have an abundance of Windows Mobile Hand Held PC's and Android Galaxy Tabs, I was trying to see if a Roo generated GWT app could run on these devices... If it were just the 1 app I was building, I would go with your suggestion though, but the issue is the variety of apps, and the turnaround required.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

That's how I end up putting myself out of a job. Rather than being sensible and rewriting the same app over and over again with variations and billing by the hour, I abstract the concept into a meta-app that can be written once and thereafter configured by monkeys.

Then they don't need me anymore.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Make Executable War File for Web App