How to share web content between eclipse projects

前端 未结 4 893
青春惊慌失措
青春惊慌失措 2021-02-07 04:28

While the J2EE module reference feature allows your to create common Java library projects, I can\'t find a neat way to do this for web content.

I have common JSPs, CSS

4条回答
  •  [愿得一人]
    2021-02-07 04:47

    I've been wrestling with the same problem for a long time, and finally stumbled onto a good solution: "Linked Folders". This is an Eclipse feature that works similarly to symlinks -- it allows you to map a single physical folder into multiple projects. The nice thing about this solution is that it doesn't require any special build steps, so Eclipse can automatically deploy changes to your local Tomcat server for testing.

    My configuration is as follows: I have an Eclipse project named "SharedContent". Inside the WebContent directory, is a subdirectory "shareRoot". All reusable files -- .jsp, .css, etc. -- are located somewhere under SharedContent/WebContent/shareRoot. This is a Dynamic Web Project so that all of the appropriate editors are enabled, but I never actually build or deploy it.

    In my other projects, I add a Linked Folder pointing to shareRoot. In Eclipse 3.6, the steps are:

    1. In the Package Explorer, right-click on the WebContent directory of the project that needs to include the reusable files.

    2. Select New -> Folder.

    3. Click the "Advanced>>>" button.

    4. Select the "Link to alternate location (Linked Folder)" radio button.

    5. In the textbox just under this, click Browse.

    6. In your source tree, navigate to SharedContent/WebContent/shareRoot. Then click OK/Open/Finish buttons until all the dialogs go away.

    The shared content is now mapped into your project. Annoyingly, you have to include "shareRoot/" in the URL when referencing these files, but you can work around this using your favorite URL rewriting filter.

    You can use a similar trick in the Java source tree to map Java files into multiple projects. I've started doing that, instead of building the shared code into a .jar file, because it avoids the need to rebuild the .jar every time you want to test a change in your local Tomcat server.

提交回复
热议问题