Eclipse: Have multiple Dynamic web projects contribute to a single war file?
I am in a situation where I basically want to be able to have a web project in Eclipse where the WebContents folder is merged from multiple projects instead of only a single dynamic web project.
If I have "a.jsp" in project A, and "b.jsp" in project B, I would like to end up with a single web application in the web container where "a.jsp" and "b.jsp" sit next to each other in the same folder. It would be perfect if all files, not just the jsp-files, could be merged like this.
This is to be able to have a core version of our application but being able to handle customer specific ch开发者_高级运维anges easily.
I know I can do this with suitable ant magic, but we want to have something that works well for our current Eclipse based development process. We will use JSR-330 dependency injection on Java classes, and essentially I'd like something along the lines of dependency injection but just for any resource and not just classes.
Can Eclipse do this?
If Eclipse cannot, would an EAR deployment be suitable perhaps? I currently have experience with WAR's only.
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 itWEBAPP_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/
精彩评论