Splitting @Eric's question in two, we have:
1) How to share common static resources such as JavaScript, CSS, and
image files without duplicating them in each web module?
By the servlet 3.0 specification, you can share resources externally putting them in the source folder src/main/resources. For this to work with dynamic files, like jsp, you should put the files inside the folder META-INF/resources. Then your shared project (jar) structure would look like this:
mymodule
| src
| | main
| | java
| | [java code]
| | resources
| | META-INF
| | resources
| | [your static and dynamic files]
If, for example, your shared js file is in src/main/resources/META-INF/resources/js/myjsfile.js it can be loaded in your html file using the path:
<script src="/js/myjsfile.js"></script>
. The same approach is valid for your css files.
Additional information: you can include a shared jsp file in your page using <jsp:include page=""/>
tag. And, if you are using Spring and have configured your viewResolver's prefix to something like '/WEB-INF/view', you must include your dynamic files inside the specified folders, that is, they would be put in the folder 'src/main/resources/META-INF/resources/WEB-INF/view'.
2) I would also like to do it in such a way that I can continue
running the web app from Eclipse and have changes I make to the
static-files automatically available to the Eclipse's running server.
Eclipse's servers plugins use the information on the 'deployment assembly' configuration of your project to keep track of the files and automatically publish changes. In your shared project, you can modify the deployment assembly in two ways: you can either a) right click in your project -> properties -> deployment assembly -> add -> folder and then choose the folder containing your files to be deployed and monitored, or b) edit the configuration file '.settings/org.eclipse.wst.common.component', adding something like
<wb-module deploy-name="mymodule">
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
If you choose the second approach, be careful, so you don't break your deployment task execution.
Additional information: if you use Maven's resources plugin for filtering resources, you probably want to add your 'target' folder in the deployment assembly, instead your 'src' folder, since the latter will contain non-filtered resources, with your properties - in the format ${my.property} - not set.