2

I have a web application that is structured into a standard war. I want to use embedded Jetty server as my servlet container. Since this is all one code base, I figured that the main() that executes the Jetty server would also be in my war with the rest of the code.

So how do I go about executing my main(), which is in the war, to launch the Jetty server? I looked at the examples but the examples do not have this setup, which to me seems like a normal setup.

Would the Jetty server need to be told where the war file is (the war file that happens to be where its also located) or would Jetty by default find and check WEB-INF for the various XML files what Jetty processes?

I see something close to this using the Jetty Maven Plugin, but the consensus is that that plugin is not for production.

Jose Martinez
  • 11,452
  • 7
  • 53
  • 68

2 Answers2

2

I was able to setup an executable file easily using the Maven plugin called Jetty Console Maven Plugin There is not much documentation about how to use it on the Internet. The author, simplercity, took down their blog entry for how to use it. But I did find one post on stackoverflow on how to use it.

The current version of this plugin is 1.55. It can be found here. One issue that I encountered is that while most of the artifacts that are required for this plugin are on version 1.55 one of them, jetty-console-ajp-plugin, is on version 1.53. This caused a problem for me because when I had all the other plugins set to 1.55 there was a signer exception error I got when I tried to execute my war. I found the solution in this stackoverflow answer. The fix was to use only 1.53 version of all the plugins. There might be a better solution that allows you to use 1.55 with 1.53 ajp-plugin. Other than that the plugin worked great and I implore the author of Jetty Console Maven Plugin to either bring his blog post on how to use it back up or create new documentation for it.

Community
  • 1
  • 1
Jose Martinez
  • 11,452
  • 7
  • 53
  • 68
1

To execute a standalone application in Java it doesn't need to be a war. A jar is fine enough. A war contains information about how a web archive/application should be deployer into a J2EE container. When you run it standalone this isn't necessary. The main method will be enough. You can have a look at maven shade plugin. It will help you build a runnable jar.

(As a sidenote - a runnable jar is a rather simple thing. The manifest file of the jar file needs to contain the key MainClass and that is it.)

froderik
  • 4,642
  • 3
  • 33
  • 43
  • 1
    Check out [this link](http://www.eclipse.org/jetty/documentation/current/using-annotations-embedded.html) from Jetty themselves. In this example they use a war as the way to implement annotations. So it looks like they keep going back to WAR file when implementing standard features of servlets. – Jose Martinez Aug 08 '14 at 13:21
  • Yes - it makes sense to have a runnable war file. In that way you can use for both purposes. (Also jetty curely needs most of the stuff typically in the war file anyway. I guess it depends on how the main method is set up and what kind of application it is.) – froderik Aug 08 '14 at 13:57