Eclipse: Have multiple Dynamic web projects contribute to a single war file?

余生长醉 提交于 2019-12-04 06:48:20
Pascal Thivent

If using Maven is an option, then Maven overlays would be perfect here and it should theoretically be supported by the m2eclipse plugin. But I don't have any experience with that and there might be some issues (see MNGECLIPSE-599) so this would require some testing.

Nevertheless, the comments of MNGECLIPSE-599 are pretty interesting, especially this one:

Any love for this issue? Our entire team has moved to Netbeans for WAR development because of this. We are basically waiting for Servlet 3.0 to solve this issue for us (Servlet 3.0 would effectively negate our need to do overlays in Maven) Our company is big on reducing copy-paste so we use overlays to manage WAR media that must be common in our apps.

The way Java EE 6 would make overlays obsolete is not crystal clear for me (through Web Fragments?) but the fact is that Eclipse's WTP release with Java EE 6 support has been delayed to June 2010. So, until then, you'll need extra tooling (e.g. maven overlays) or should maybe consider switching to NetBeans.

I had a similar use case which I successfully resolved by using (as Pascal suggested) Maven. I have a root web project (which also works standalone) and for each client I have a separate web project which is configured to overlay with the root web project. Furthermore, since each client has several environments I created a maven profile for each environment (test, prod, local, ...). I documented this a bit so if ever you are interested I don't mind mailing you the doc.

  • you don't need to change your "eclipse based development process" to use ant. Just register an Ant builder (right click project > Properties > Builders) and integrate the ant script with your eclipse process
  • you can use maven's multi-module options. (The maven plugin for eclipse is very good as well)
  • use can also use FileSync - not industry-standard but pretty powerful. It's used for developing on localhost, of course.

Here are a few tips for using FileSync:

  • setup which files/file patterns/dirs to copy to a target directory (Tomcat's webapps/application in your case). So as soon as you press "save", the files are copied.
  • make all absolute paths in the FileSync.xxxx.prefs relative by introducing a Linked Resource (preferences > workspace > linked resources), and using the link resource variable in the prefs file (lets call it WEBAPP_HOME)
  • commit the FileSync.xxxx.prefs file
  • tell each developer on the team to configure the WEBAPP_HOME variable. Thus the setup will not be valid for only one machine, but for each machine in the team.

I recommend to use the servlet 3.0 "Resources in bundled jar files" feature. With this feature you can include web resources (html/xhtml/css/js/jpg/etc) in jar files (along with java class files, of course) and the web server will search the "META-INF/resources" folders of the jars for the resources.

More details here:

http://alvinjayreyes.com/2013/07/28/servlet-3-0/

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