Embedded Jetty : how to use a .war that is included in the .jar from which Jetty starts?

ⅰ亾dé卋堺 提交于 2019-12-05 11:42:15

I played with this a lot in 2009-10 for a specific app.

The problem I found is that when you have a war embedded within a jar, the URIs can end up being ones that do not work with the default jar: uri handler trying to access the war file.

There are a number of solutions that I found:

  1. Tell jetty to extract/explode the war file into a temporary directory

  2. Implement your own URI handler (that was an interesting exercise, but if you need to support the code yourself, I would not recommend doing that)

  3. Make the war file an executable war file, e.g. the same type of trick used by Jenkins. To do this you overlay the jetty server classes and your main class with the war file. Then you just point jetty to the jar file itself as the war file. Jetty does not care that the filename does not end in .war

All three worked for me on Jetty 7. I suspect that the situation will remain the same.

In the end I opted for option 3. It works out as the simplest, does not leave temporary files on the users system, and is quickest to start up.

I have tried like you with a war file inside the jar but jetty seemed to serve me a directory listing with the war file as the only entry, which I found weird... Not sure if I've done something wrong there...

I have found that exploding the war file in a directory inside the jar file seemed to work for me so far. I may unearth some weird things later on but until I do, I'll stick with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!